You have to use getTableQuery
method for that. This method returns Eloquent Builder or Relation class but for our situation it's going to return Builder class. So we can use that builder to add our queries.
For example i have a relation manager that must be ordered by order_column.
- Open your relation manager file.
- Then add this code:
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
protected function getTableQuery(): Builder|Relation
{
return parent::getTableQuery()->orderBy('order_column');
}
- Save and check.
Top comments (1)
In Filament 3.*, to customize the query for a RelationManager (e.g., to always order by the attempt column descending), the recommended way to override the query is:
This ensures the related records are consistently ordered without running into null issues, and it's fully compatible with Filament 3's structure.