Eloquent query using integers not working in Filament context

When using a custom query builder/scope with a scope like this:
public function inProject(int $projectId): self
{
return $this->where('project_id', $projectId);
}
public function inProject(int $projectId): self
{
return $this->where('project_id', $projectId);
}
and using it in a resource like this:
public static function getEloquentQuery(): Builder
{
$projectId = 1234356789; // This is an snowflake integer id
/** @var ProjectQueryBuilder $query */
$query = parent::getEloquentQuery();

return $query
->inProject($projectId);
}
public static function getEloquentQuery(): Builder
{
$projectId = 1234356789; // This is an snowflake integer id
/** @var ProjectQueryBuilder $query */
$query = parent::getEloquentQuery();

return $query
->inProject($projectId);
}
Filament does not retrieve anything. The project_id is an unsignedBigInteger. When using the same query scope outside of Filament context, the opposite would be true - and the query parameter would have to be cast to integer to retrieve the right data. What in Filament is causing this behavior? Is it intended behavior or a bug? Does anyone have a suggestion for a fix?
2 Replies
Dennis Koch
Dennis Koch2mo ago
Can you check the actual SQL query via Debugbar or similar?
nicolaibaaring
nicolaibaaringOP2mo ago
A simple builder dd() gives this:
"
select * from `tasks` where `project_id` = ? and (`status` in (?, ?, ?, ?) or (`status` = ? and `created_by` = ?)) and `tasks`.`deleted_at` is null

" // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:4406
array:7 [▼ // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:4406
0 => 287885550034231034
1 => 2
2 => 4
3 => 8
4 => 9
5 => 0
6 => 287885378390727198
]
"
select * from `tasks` where `project_id` = ? and (`status` in (?, ?, ?, ?) or (`status` = ? and `created_by` = ?)) and `tasks`.`deleted_at` is null

" // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:4406
array:7 [▼ // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:4406
0 => 287885550034231034
1 => 2
2 => 4
3 => 8
4 => 9
5 => 0
6 => 287885378390727198
]
So these are all integers. In this case, the table query works, and gives the right results, but clicking a row to open the modal (this is a simple resource) does not open the modal (same as ModelNotFound). I might have mentioned it wrong above, because the missing models in the table vs the infolist/form depends on which params are cast to string. If I add a method to my custom query builder that converts all numeric params to string, then both the table and the infolist/form works as intended. Just as an additional note, this is using MySQL and the database strict setting does not change anything. The problem is only found when using integers and when the query is running in a Filament context.
Want results from more Discord servers?
Add your server