schema([ Forms\Components\Select::make('mode') ->options(SearchBox::listModeOptions()) ->label(__('label.search_box.label')) ->rules([ 'required', function () { return function ($attribute, $value, $fail) { //@todo how to get the editing record ? $exists = Torrent::query()->where('category', $value)->exists(); do_log("check $attribute: $value torrent if exists: $exists"); // if ($exists) { // $fail("There are torrents belonging to this category that cannot be changed!"); // } }; } ]) , Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name'))->required(), Forms\Components\TextInput::make('image') ->label(__('label.search_box.taxonomy.image')) ->helperText(__('label.search_box.taxonomy.image_help')) ->required() , Forms\Components\Select::make('icon_id') ->options(Icon::query()->pluck('name', 'id')->toArray()) ->label(__('label.search_box.taxonomy.icon_id')) ->required() , Forms\Components\TextInput::make('class_name') ->label(__('label.search_box.taxonomy.class_name')) ->helperText(__('label.search_box.taxonomy.class_name_help')) , Forms\Components\TextInput::make('sort_index') ->default(0) ->label(__('label.priority')) ->helperText(__('label.priority_help')) , ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id'), Tables\Columns\TextColumn::make('search_box.name')->label(__('label.search_box.label')), Tables\Columns\TextColumn::make('name')->label(__('label.search_box.taxonomy.name'))->searchable(), Tables\Columns\TextColumn::make('icon.name')->label(__('label.search_box.taxonomy.icon_id')), Tables\Columns\TextColumn::make('image')->label(__('label.search_box.taxonomy.image')), Tables\Columns\TextColumn::make('class_name')->label(__('label.search_box.taxonomy.class_name')), Tables\Columns\TextColumn::make('sort_index')->label(__('label.priority'))->sortable(), ]) ->defaultSort('sort_index', 'desc') ->filters([ Tables\Filters\SelectFilter::make('mode') ->options(SearchBox::query()->pluck('name', 'id')->toArray()) ->label(__('label.search_box.label')) , ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make()->using(function (NexusModel $record) { try { $rep = new SearchBoxRepository(); $rep->deleteCategory($record->id); } catch (\Exception $exception) { Filament::notify('danger', $exception->getMessage() ?: class_basename($exception)); } }), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make()->using(function (Collection $records) { try { $rep = new SearchBoxRepository(); $rep->deleteCategory($records->pluck('id')->toArray()); } catch (\Exception $exception) { Filament::notify('danger', $exception->getMessage() ?: class_basename($exception)); } }), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListCategories::route('/'), 'create' => Pages\CreateCategory::route('/create'), 'edit' => Pages\EditCategory::route('/{record}/edit'), ]; } }