F
Filament16mo ago
imsus

Has anyone successfully integrating admin panel with Laravel Scout yet?

These are the code I implement on Filament Resource Class:
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label('ID')
->searchable(), // make sure one table has searchable
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
])
->emptyStateActions([
// ...
])
->modifyQueryUsing(function (Builder $query) use ($table): Builder {
// This is where I implement the search function
return $query->whereIn('id', User::search($table->getQueryStringIdentifier('tableSearch'))->keys());
});
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label('ID')
->searchable(), // make sure one table has searchable
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
])
->emptyStateActions([
// ...
])
->modifyQueryUsing(function (Builder $query) use ($table): Builder {
// This is where I implement the search function
return $query->whereIn('id', User::search($table->getQueryStringIdentifier('tableSearch'))->keys());
});
}
My question, even though I doing these it still cannot find result. I found these on docs but this is for building table component not integrating with panel table. https://filamentphp.com/docs/3.x/tables/advanced#searching-records-with-laravel-scout
Solution:
Found it, so this is the correct way On table() function ```php...
Jump to solution
1 Reply
Solution
imsus
imsus16mo ago
Found it, so this is the correct way On table() function
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')->label('ID')->searchable(query: fn (Builder $query): Builder => $query),
// 1. At least there is 1 searchable columns to show search field
// 2. The callback should return NON-MODIFIED $query. By default filament will add ->where('id', 'like', '%$value%') on every searchable column.
])
->modifyQueryUsing(function (Builder $query) use ($table): Builder {
$search = str($table->getSearchIndicator())->after(': ')->__toString();
// 3. This is the only way that I can get the search query inputted.

return $query->whereIn('id', YourSearchableModel::search($search)->keys());
})
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')->label('ID')->searchable(query: fn (Builder $query): Builder => $query),
// 1. At least there is 1 searchable columns to show search field
// 2. The callback should return NON-MODIFIED $query. By default filament will add ->where('id', 'like', '%$value%') on every searchable column.
])
->modifyQueryUsing(function (Builder $query) use ($table): Builder {
$search = str($table->getSearchIndicator())->after(': ')->__toString();
// 3. This is the only way that I can get the search query inputted.

return $query->whereIn('id', YourSearchableModel::search($search)->keys());
})
}
Want results from more Discord servers?
Add your server