Skip to content

Commit 561904a

Browse files
authored
Merge pull request #14 from TappNetwork/form-show-bug
Middleware for form show that handles guest entries
2 parents a24dcb1 + 3df01a7 commit 561904a

File tree

13 files changed

+51
-13
lines changed

13 files changed

+51
-13
lines changed

.DS_Store

-8 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ phpstan.neon
99
testbench.yaml
1010
vendor
1111
node_modules
12+
.DS_Store
13+
**/.DS_Store

database/.DS_Store

-6 KB
Binary file not shown.

routes/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
use Illuminate\Support\Facades\Route;
44
use Tapp\FilamentFormBuilder\Livewire\FilamentForm\Form as FilamentForm;
55
use Tapp\FilamentFormBuilder\Livewire\FilamentFormUser\Entry as FilamentFormUserEntry;
6+
use Tapp\FilamentFormBuilder\Middleware\CheckFormGuestAccess;
67

78
Route::get(config('filament-form-builder.filament-form-user-uri').'/{entry}', FilamentFormUserEntry::class)
89
->middleware('web')
910
->name('filament-form-users.show');
1011

1112
Route::get(config('filament-form-builder.filament-form-uri').'/{form}', FilamentForm::class)
12-
->middleware('web')
13+
->middleware(['web', CheckFormGuestAccess::class])
1314
->name('filament-form-builder.show');

src/.DS_Store

-6 KB
Binary file not shown.

src/Enums/FilamentFieldTypeEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function fromString(string $type): ?self
3232
return null; // Return null if no match is found
3333
}
3434

35-
public function getLabel(): ?string
35+
public function getLabel(): string
3636
{
3737
return $this->fieldName();
3838
}

src/Exports/FilamentFormUsersExport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function map($entry): array
3737
];
3838

3939
foreach ($this->form->filamentFormFields as $field) {
40+
/** @phpstan-ignore-next-line */
4041
$entriesFieldKey = array_search($field->id, array_column($entry->entry, 'field_id'));
4142

4243
if ($entriesFieldKey === false) {
@@ -58,6 +59,7 @@ public function headings(): array
5859
];
5960

6061
foreach ($this->form->filamentFormFields as $field) {
62+
/** @phpstan-ignore-next-line */
6163
array_push($headings, $field->label);
6264
}
6365

src/Livewire/FilamentForm/Form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function mount(FilamentForm $form)
1616

1717
public function render()
1818
{
19+
/** @phpstan-ignore-next-line */
1920
return view('filament-form-builder::livewire.filament-form.form');
2021
}
2122
}

src/Livewire/FilamentForm/Show.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Tapp\FilamentFormBuilder\Enums\FilamentFieldTypeEnum;
1313
use Tapp\FilamentFormBuilder\Events\EntrySaved;
1414
use Tapp\FilamentFormBuilder\Models\FilamentForm;
15-
use Tapp\FilamentFormBuilder\Models\FilamentFormField;
1615
use Tapp\FilamentFormBuilder\Models\FilamentFormUser;
1716

1817
/**
@@ -40,10 +39,6 @@ public function mount(FilamentForm $form, bool $blockRedirect = false, bool $pre
4039
$this->form->fill($this->data);
4140

4241
$this->blockRedirect = $blockRedirect;
43-
44-
if (! $this->filamentForm->permit_guest_entries && ! Auth::check()) {
45-
return redirect('/', 401);
46-
}
4742
}
4843

4944
public function form(Form $form): Form
@@ -57,6 +52,7 @@ public function getSchema(): array
5752
{
5853
$schema = [];
5954

55+
/** @var \Tapp\FilamentFormBuilder\Models\FilamentFormField $fieldData */
6056
foreach ($this->filamentForm->filamentFormFields as $fieldData) {
6157
$filamentField = $fieldData->type->className()::make($fieldData->id);
6258

@@ -118,10 +114,15 @@ public function create()
118114
$entry = [];
119115

120116
foreach ($this->form->getState() as $key => $value) {
117+
/** @var \Tapp\FilamentFormBuilder\Models\FilamentFormField|null $field */
121118
$field = $this->filamentForm
122119
->filamentFormFields
123120
->find($key);
124121

122+
if (! $field) {
123+
continue;
124+
}
125+
125126
$valueData = $this->parseValue($field, $value);
126127

127128
array_push($entry, [
@@ -153,6 +154,7 @@ public function create()
153154

154155
// Handle file uploads
155156
foreach ($this->filamentForm->filamentFormFields as $field) {
157+
/** @var \Tapp\FilamentFormBuilder\Models\FilamentFormField $field */
156158
if ($field->type === FilamentFieldTypeEnum::FILE_UPLOAD) {
157159
$fileKey = $field->id;
158160
$fileData = $this->data[$fileKey] ?? null;
@@ -193,7 +195,7 @@ public function create()
193195
}
194196
}
195197

196-
public function parseValue(FilamentFormField $field, string|array|null $value): string|array
198+
public function parseValue(\Tapp\FilamentFormBuilder\Models\FilamentFormField $field, string|array|null $value): string|array
197199
{
198200
if ($value === null && ! $field->type->isBool()) {
199201
return '';
@@ -216,6 +218,7 @@ public function parseValue(FilamentFormField $field, string|array|null $value):
216218

217219
public function render()
218220
{
221+
/** @phpstan-ignore-next-line */
219222
return view('filament-form-builder::livewire.filament-form.show');
220223
}
221224
}

src/Livewire/FilamentFormUser/Entry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function mount(FilamentFormUser $entry)
1616

1717
public function render()
1818
{
19+
/** @phpstan-ignore-next-line */
1920
return view('filament-form-builder::livewire.filament-form-user.entry');
2021
}
2122
}

0 commit comments

Comments
 (0)