Skip to content

Commit 7145c19

Browse files
committed
feat: add 'fillFromExist' action to category selection in NavigationResource
1 parent 4c012b9 commit 7145c19

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Filament/Resources/NavigationResource.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,38 @@ protected static function getCategoryFormComponent()
262262
'footer',
263263
])
264264
->default('main')
265+
->suffixActions([
266+
Forms\Components\Actions\Action::make('fillFromExist')
267+
->icon('heroicon-o-pencil')
268+
->fillForm(fn ($state) => [
269+
'category' => $state,
270+
])
271+
->form(function () {
272+
$getCategoryOptions = function ($search = null, $limit = 50) {
273+
$query = static::getEloquentQuery()
274+
->select('category')
275+
->distinct()
276+
->when($search, function ($query, $search) {
277+
$query->where('category', 'like', '%' . $search . '%');
278+
})
279+
->limit($limit);
280+
return $query->pluck('category', 'category')->all();
281+
};
282+
return [
283+
Forms\Components\Select::make('category')
284+
->label(__('inspirecms::resources/navigation.category.label'))
285+
->validationAttribute(__('inspirecms::resources/navigation.category.validation_attribute'))
286+
->options(fn () => $getCategoryOptions())
287+
->searchable()
288+
->getSearchResultsUsing(fn ($search) => $getCategoryOptions($search))
289+
->default(fn ($record, $get) => $get('category'))
290+
->required(),
291+
];
292+
})
293+
->action(function ($data, $set) {
294+
$set('category', $data['category']);
295+
}),
296+
])
265297
->live()
266298
->afterStateUpdated(function ($old, $state, $set) {
267299
if (trim($old) !== trim($state)) {

0 commit comments

Comments
 (0)