1 month ago

Best Laravel Eloquent tutorial for searching

Posted 1 month ago by chrisgrim

Hi, Right now I am using pretty simple code for a search

 public function search(Request $request)
        $searchTerm = $request->keywords;
        $ajaxOrganizers = Organizer::where('name', 'LIKE', "%{$searchTerm}%")->limit(30)->get()->toArray();

        return response()->json($ajaxOrganizers);

I had two questions. First, I wanted to make sure this was the fastest and cleanest way to search. Second I was reading this article and wondering if it still a good way to do it. (The article was written almost 4 years ago) If not, is there a cleaner way to search a model?


Please sign in or create an account to participate in this conversation.