I'm trying to build a search functionality in my laravel app. I want to search on the name of a tag that is related with a pivot table to my loops. But I get the error 'undefined variable : query'
This is my controller method :
public function search($query) {
$searchResult = Loop::whereHas('tags', function ($q) {
$q->where('name', 'LIKE', '%'. $query .'%');
})->get();
return Response::json($searchResult);
}