Debug Filament Search Query



This content originally appeared on DEV Community and was authored by Ariel Mejia

Filament Resources allow to create quickly tables by mapping objects, it allows to add easily pretty common features like:

  • sortable
  • searchable
  • and more features

in this case to debug the search query we can check the List class that is created by default when a user creates a filament resource, eg:

User Resource

class UserResource extends Resource
{
    protected static ?string $model = User::class;

    public static function getPages(): array
    {
        return [
            'index' => ListUsers::route('/'),
            // ... more pages
        ];
    }
}

ListUsers

Here we can override a getFilteredTableQuery method to check the raw sql and debug the query

protected function getFilteredTableQuery(): Builder
{
    dd(parent::getFilteredTableQuery()->toRawSql());
}

Hope it is useful & Happy Coding!


This content originally appeared on DEV Community and was authored by Ariel Mejia