Skip to content

Commit 1a7bf3f

Browse files
committed
Fallback for missing resource array key
1 parent c6868db commit 1a7bf3f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Concerns/HasOptions.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public static function addOptionsToInput(mixed $input, mixed $field): mixed
2323
$model = $res->getModel();
2424
$model = new $model;
2525

26+
if (!isset($relation['resource'])) {
27+
return false;
28+
}
29+
2630
return $model->getTable() === $relation['resource'];
2731
});
2832

@@ -105,8 +109,8 @@ public function optionFormFields(): Fieldset
105109
Forms\Components\KeyValue::make('config.options')
106110
->label(__('Options'))
107111
->columnSpanFull()
108-
->visible(fn (Forms\Get $get): bool => $get('config.optionType') == 'array')
109-
->required(fn (Forms\Get $get): bool => $get('config.optionType') == 'array'),
112+
->visible(fn(Forms\Get $get): bool => $get('config.optionType') == 'array')
113+
->required(fn(Forms\Get $get): bool => $get('config.optionType') == 'array'),
110114
// Relationship options
111115
Repeater::make('config.relations')
112116
->label(__('Relations'))
@@ -165,19 +169,19 @@ public function optionFormFields(): Fieldset
165169
->toArray();
166170
})
167171
->noSearchResultsMessage(__('No types found'))
168-
->required(fn (Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
172+
->required(fn(Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
169173
Forms\Components\Hidden::make('relationKey')
170174
->default('ulid')
171175
->label(__('Key'))
172-
->required(fn (Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
176+
->required(fn(Forms\Get $get): bool => $get('config.optionType') == 'relationship'),
173177
Forms\Components\Repeater::make('relationValue_filters')
174178
->label(__('Filters'))
175-
->visible(fn (Forms\Get $get): bool => ! empty($get('resource')))
179+
->visible(fn(Forms\Get $get): bool => ! empty($get('resource')))
176180
->schema([
177181
Forms\Components\Grid::make(3)
178182
->schema([
179183
Forms\Components\Select::make('column')
180-
->options(fn (\Filament\Forms\Get $get) => $get('../../relationValue_options') ?? [
184+
->options(fn(\Filament\Forms\Get $get) => $get('../../relationValue_options') ?? [
181185
'slug' => __('Slug'),
182186
'name' => __('Name'),
183187
])
@@ -232,7 +236,7 @@ public function optionFormFields(): Fieldset
232236
->columnSpanFull(),
233237
]),
234238
])
235-
->visible(fn (Forms\Get $get): bool => $get('config.optionType') == 'relationship')
239+
->visible(fn(Forms\Get $get): bool => $get('config.optionType') == 'relationship')
236240
->columnSpanFull(),
237241
]),
238242
]);

0 commit comments

Comments
 (0)