DEV Community

Discussion on: How to implement search functionality in laravel 8 and laravel 7 downwards

Collapse
 
msamgan profile image
Mohammed Samgan Khan

nice article. good job.
but a much easier way can be as follows.

public function index()
{
        $project = Project::query();
        if (request('term')) {
            $project->where('name', 'Like', '%' . request('term') . '%');
        }

        return $project->orderBy('id', 'DESC')->paginate(10);
}
Enter fullscreen mode Exit fullscreen mode

IN laravel you can break the query in pieces.