diff --git a/app/Filament/Resources/Section/CategoryResource.php b/app/Filament/Resources/Section/CategoryResource.php index 81f6c459..8f995a14 100644 --- a/app/Filament/Resources/Section/CategoryResource.php +++ b/app/Filament/Resources/Section/CategoryResource.php @@ -8,6 +8,7 @@ use App\Models\Category; use App\Models\Icon; use App\Models\NexusModel; use App\Models\SearchBox; +use App\Models\Torrent; use App\Repositories\SearchBoxRepository; use Filament\Facades\Filament; use Filament\Forms; @@ -46,7 +47,19 @@ class CategoryResource extends Resource Forms\Components\Select::make('mode') ->options(SearchBox::listModeOptions()) ->label(__('label.search_box.label')) - ->required() + ->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') diff --git a/app/Repositories/MeiliSearchRepository.php b/app/Repositories/MeiliSearchRepository.php index c25d2894..1c419162 100644 --- a/app/Repositories/MeiliSearchRepository.php +++ b/app/Repositories/MeiliSearchRepository.php @@ -267,13 +267,21 @@ class MeiliSearchRepository extends BaseRepository $torrentIdArr = array_column($searchResult->getHits(), 'id'); $fields = Torrent::getFieldsForList(); $idStr = implode(',', $torrentIdArr); - $results['list'] = Torrent::query() + $torrents = Torrent::query() ->select($fields) + ->with('basic_category') ->whereIn('id', $torrentIdArr) ->orderByRaw("field(id,$idStr)") ->get() - ->toArray() ; + $list = []; + foreach ($torrents as $torrent) { + $searchBoxId = $torrent->basic_category->mode; + $arr = $torrent->toArray(); + $arr['search_box_id'] = $searchBoxId; + $list[] = $arr; + } + $results['list'] = $list; } return $results; } diff --git a/include/constants.php b/include/constants.php index 9886456e..7250549e 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@