chrisgrim
4 weeks ago
177
5
Laravel

Best Laravel Eloquent tutorial for searching

Posted 4 weeks 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 https://m.dotdev.co/writing-advanced-eloquent-search-query-filters-de8b6c2598db 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?

Thanks!

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