searchable/filterable method with parameter does not work on relation field in filters
webard opened this issue · 3 comments
- Laravel Version: 11.7.0
- Nova Version: 4.33
- PHP Version: 8.2.17
- Database Driver & Version: 8.3.0
- Operating System and Version: MacOS 14.4.1
- Browser type and version: Chrome 124.0.6367.203
Description:
I have field named "Owner" which is simply User:
BelongsTo::make(___('Owner'), 'owner', User::class)
->filterable(function(NovaRequest $request, Builder $query, string $value) {
return $query->where('is_owner', true);
})
but query from parameter seems to not work during searching in filter:
It seems to query data basing on $search
property in User
resource, but does not respect extension of builder from closure.
Generated query is:
select * from `users` where (`users`.`id` like '%admin%' or `users`.`fullname` like '%admin%' or `users`.`email` like '%admin%' or `users`.`phone` like '%admin%') and `users`.`deleted_at` is null order by `updated_at` desc
but should be
select * from `users` where (`users`.`id` like '%admin%' or `users`.`fullname` like '%admin%' or `users`.`email` like '%admin%' or `users`.`phone` like '%admin%') and `users`.`is_owner` = 1 and `users`.`deleted_at` is null order by `updated_at` desc
Detailed steps to reproduce the issue on a fresh Nova installation:
- Configure filterable relation field and pass in argument closure with additional builder conditions
The query you shown above are for searching the dropdown, while
->filterable(function(NovaRequest $request, Builder $query, string $value) {
return $query->where('is_owner', true);
})
will be only be applied to the current resource SQL. Such as
SELECT * FROM `posts` WHERE `is_owner`=1
instead of the default
SELECT * FROM `posts` WHERE `user_id`=?
@crynobone I know that. Why you closed issue without even identyfing use cases?
When we search relation from Edit view, in request data there is info about component, relationship etc. so we can use it to manage query in indexQuery() method.
When searching in filters, there is just /nova-api/resource/search without any additional data like resource, filter name etc. It will be enough to manage search query and it is not breaking change, just couple additional parameters in URL during filter searching.
This change cannot be planned?