Reputation: 119
I am trying to create search function but showing nothing from search
public function search(Request $request)
{
$search = $request->get('search');
$dictionaries = Dictionary::all()->where('title', 'LIKE', "%{$search}%");
return view('dictionary', compact('dictionaries'));
}
Upvotes: 0
Views: 54
Reputation: 29314
You can't call ::all()
before ->where()
in this manner. You need to restructure your query:
$dictionaries = Dictionary::where('title', 'LIKE', "%{$search}%")->get();
When you call ::all()
, you're converting your Dictionary
query to a Collection
, and the ->where()
method on a Collection
is different than that of the Builder
class.
Upvotes: 5