|
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,18 @@ 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 | + return $query->whereRaw("LOWER(title->>'$.{$locale}') LIKE ?", ["%{$search}%"]); |
| 193 | + }), |
183 | 194 | TextColumn::make('created_at')
|
184 | 195 | ->label(flexiblePagesTrans('pages.table.created_at_col'))
|
185 | 196 | ->dateTime(FilamentFlexibleBlocksConfig::getPublishingDateFormatting())
|
186 | 197 | ->sortable(),
|
187 |
| - PublishedColumn::create(), |
| 198 | + PublishedColumn::create() |
| 199 | + ->sortable(), |
188 | 200 | ])
|
189 | 201 | ->filters([
|
190 | 202 | PublishedFilter::create(),
|
@@ -220,4 +232,36 @@ public static function getPages(): array
|
220 | 232 | 'edit' => EditPage::route('/{record:id}/edit'),
|
221 | 233 | ];
|
222 | 234 | }
|
| 235 | + |
| 236 | + public static function getGloballySearchableAttributes(): array |
| 237 | + { |
| 238 | + return [ |
| 239 | + 'title', |
| 240 | + 'intro', |
| 241 | + 'content_blocks', |
| 242 | + 'seo_title', |
| 243 | + 'seo_description', |
| 244 | + 'seo_keywords' |
| 245 | + ]; |
| 246 | + } |
| 247 | + |
| 248 | + public static function getGlobalSearchResultTitle(Model $record): string |
| 249 | + { |
| 250 | + return $record->getTranslation('title', app()->getLocale()); |
| 251 | + } |
| 252 | + |
| 253 | + public static function getGlobalSearchResultDetails(Model $record): array |
| 254 | + { |
| 255 | + $published = trans('filament-flexible-content-blocks::filament-flexible-content-blocks.columns.is_published_state_unpublished'); |
| 256 | + if ($record->isPublished()) { |
| 257 | + $published = trans( |
| 258 | + 'filament-flexible-content-blocks::filament-flexible-content-blocks.columns.is_published_state_published' |
| 259 | + ); |
| 260 | + } |
| 261 | + |
| 262 | + return [ |
| 263 | + trans('filament-flexible-content-blocks::filament-flexible-content-blocks.form_component.intro_lbl') => Str::limit(strip_tags($record->intro)), |
| 264 | + trans('filament-flexible-content-blocks::filament-flexible-content-blocks.columns.is_published') => $published |
| 265 | + ]; |
| 266 | + } |
223 | 267 | }
|
0 commit comments