Closed Kamleshpaul closed 3 years ago
@Kamleshpaul Hi
I can't understand what is the problem. *
means all fields can be in the filter. Please explain more
the problem is how can we remove You must set $field in whiteListFilter
this error ?
in production we can't throw this error
@Kamleshpaul If you use eloquent filter in your model you must set whiteListFilter
array when calling the filter method.
@mehdi-fathi
i added $whiteListFilter = ['id']
this in my model
and when i try in route ?foo=baar
it is giving me 500 error as You must set $field in whiteListFilter
here i want only id
means ?id
should only handel by library not foo
@Kamleshpaul you didn’t read readme carefully. Eloquent filter has a method to ignore some param. For example
User::ignoreRequest(['perpage'])->filter() ->paginate(request()->get('perpage'), ['*'], 'page')
ignoreRequest
i m using
but my problem is let's say i handel User::ignoreRequest(['foo'])->filter()
in this case foo
will be ignored by library but if user my enter any words which we cannot predict , it is throwing 500 error
so my point is here
only search for $whiteListFilter
these words and exclude all don't throw 500 error like You must set $field in whiteListFilter
or make any config
like env=production
will not throw 500 error only env=local
will throw 500
@Kamleshpaul Ok you are right. But you can handle it in your controller. I try to make a feature for this problem in the later version.
yes i can handle it but i found it will be easy to skip in main library itself i guess so i created this issue
thank you 😊
@Kamleshpaul Thanks
@Kamleshpaul update package to new version
User::AcceptRequest(['username','id'])
->filter()
->paginate(request()->get('perpage'), ['*'], 'page');
Call AcceptRequest
will accept requests that you want to use in conditions eloquent filter.
For example username
and id
param will be in the conditions eloquent filter. Just notice you must set $whiteListFilter
in Model. This method is useful for query string manipulation by user.
@mehdi-fathi thank you so much for this feature , you save my time 👍
HI Author,
i m using this, it so far is very good and helpful but now i m getting on issue with it.
when i set in model
$whiteListFilter = ['id']
it should mean
?id
will handle by this library rest user can handle own but now it is looking for?anykey
it should happen if user$whiteListFilter = ['*']
add like thisblow is the code which you need to look
https://github.com/mehdi-fathi/eloquent-filter/blob/c576a1a44c1b51ca371db177e83e9694a75bb72b/src/QueryFilter/Detection/DetectorConditions.php#L77
Thanks you