middleware("web"); } public function search(Request $request) { $queries = explode(" ", $request->q); $result = collect(); foreach ($queries as $query) { $result->push(Post::where([ "is_confirmed" => true, "is_active" => true, ]) ->where("title", "like", "%{$query}%") ->get()); } $result = $result->flatten(); return view("blog.search") ->with("searchQuery", $request->q) ->with("results", $result); } }