Skip to content

How to fix search and sort in eloquent relationship? #561

Closed Answered by gal01azabolcs
mahdijafaridev asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, I think maybe this can help for you:
->searchable(function ($builder, $term) {
return $builder->orWhereHas('restaurant',function($query) use($term){
$query->where('name', 'LIKE', '%' . $term . '%');
});
})
->sortable(function(Builder $query, $direction) {
return $query->orderBy(Restaurant::select('name')->whereColumn('products.restaurant_id', 'restaurants.id'), $direction);
}),

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by mahdijafaridev
Comment options

You must be logged in to vote
1 reply
@gal01azabolcs
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants