|
12 | 12 | use Filament\Tables\Columns\TextColumn;
|
13 | 13 | use Filament\Tables\Table;
|
14 | 14 | use Illuminate\Database\Eloquent\Builder;
|
| 15 | +use Illuminate\Database\Eloquent\Model; |
| 16 | +use Illuminate\Support\Str; |
15 | 17 | use Statikbe\FilamentFlexibleContentBlockPages\Actions\LinkedToMenuItemBulkDeleteAction;
|
16 | 18 | use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
|
17 | 19 | use Statikbe\FilamentFlexibleContentBlockPages\Resources\PageResource\Pages\CreatePage;
|
@@ -47,6 +49,10 @@ class PageResource extends Resource
|
47 | 49 |
|
48 | 50 | protected static ?string $recordTitleAttribute = 'title';
|
49 | 51 |
|
| 52 | + protected static int $globalSearchResultsLimit = 10; |
| 53 | + |
| 54 | + protected static ?bool $isGlobalSearchForcedCaseInsensitive = true; |
| 55 | + |
50 | 56 | public static function getModel(): string
|
51 | 57 | {
|
52 | 58 | return FilamentFlexibleContentBlockPages::config()->getPageModel()::class;
|
@@ -179,12 +185,19 @@ public static function table(Table $table): Table
|
179 | 185 | {
|
180 | 186 | return $table
|
181 | 187 | ->columns([
|
182 |
| - TitleColumn::create(), |
| 188 | + TitleColumn::create() |
| 189 | + ->searchable(query: function ($query, $search) { |
| 190 | + $locale = app()->getLocale(); |
| 191 | + $search = strtolower($search); |
| 192 | + |
| 193 | + return $query->whereRaw("LOWER(title->>'$.{$locale}') LIKE ?", ["%{$search}%"]); |
| 194 | + }), |
183 | 195 | TextColumn::make('created_at')
|
184 | 196 | ->label(flexiblePagesTrans('pages.table.created_at_col'))
|
185 | 197 | ->dateTime(FilamentFlexibleBlocksConfig::getPublishingDateFormatting())
|
186 | 198 | ->sortable(),
|
187 |
| - PublishedColumn::create(), |
| 199 | + PublishedColumn::create() |
| 200 | + ->sortable(), |
188 | 201 | ])
|
189 | 202 | ->filters([
|
190 | 203 | PublishedFilter::create(),
|
@@ -220,4 +233,38 @@ public static function getPages(): array
|
220 | 233 | 'edit' => EditPage::route('/{record:id}/edit'),
|
221 | 234 | ];
|
222 | 235 | }
|
| 236 | + |
| 237 | + public static function getGloballySearchableAttributes(): array |
| 238 | + { |
| 239 | + return [ |
| 240 | + 'title', |
| 241 | + 'intro', |
| 242 | + 'content_blocks', |
| 243 | + 'seo_title', |
| 244 | + 'seo_description', |
| 245 | + 'seo_keywords', |
| 246 | + 'overview_title', |
| 247 | + 'overview_description', |
| 248 | + ]; |
| 249 | + } |
| 250 | + |
| 251 | + public static function getGlobalSearchResultTitle(Model $record): string |
| 252 | + { |
| 253 | + return $record->getTranslation('title', app()->getLocale()); |
| 254 | + } |
| 255 | + |
| 256 | + public static function getGlobalSearchResultDetails(Model $record): array |
| 257 | + { |
| 258 | + $published = trans('filament-flexible-content-blocks::filament-flexible-content-blocks.columns.is_published_state_unpublished'); |
| 259 | + if ($record->isPublished()) { |
| 260 | + $published = trans( |
| 261 | + 'filament-flexible-content-blocks::filament-flexible-content-blocks.columns.is_published_state_published' |
| 262 | + ); |
| 263 | + } |
| 264 | + |
| 265 | + return [ |
| 266 | + trans('filament-flexible-content-blocks::filament-flexible-content-blocks.form_component.intro_lbl') => Str::limit(strip_tags($record->intro)), |
| 267 | + trans('filament-flexible-content-blocks::filament-flexible-content-blocks.columns.is_published') => $published, |
| 268 | + ]; |
| 269 | + } |
223 | 270 | }
|
0 commit comments