Closed devchalkie closed 4 years ago
Yup, you can do that if you switch to calling books
as a method so you still have access to the related query before it's executed.
This should do the trick:
$user->books()->filter($request->all())->get();
Thank you a lot, that makes it a lot easier :) awesome work. 👍
Don't work for me
$searches = $user->searches()->filter($request->all())->get();
Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::filter()
@bitdev1999 I have the same issue. Any suggestions @Tucker-Eric?
@benrolfe In that case he relation needs to use the Filterable
trait. So the model that searches
returns in the relationship needs to implement that Filterable
trait.
Hi, I have User model which has relationship say books(), i want to do something like $user->books->filter($request->all()) so that user can only filter through his books.
Any suggestion please.
Thanks, Hussain