How to Use Where Like Query in Laravel 8?

Laravel 7/6 Where Like Query Example

Today now in this example,I will show you how to use where like query in laravel 8 application. We can simply and easy to define about where like query in laravel 7/6.

Laravel 8 provide query builder and mysql like condition is very simple to use.Just bellow example

Example 1 :-

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $search = "raj";
    
    $users = User::where('name', 'LIKE', "%$search%")
                ->latest()
                ->get();

    dd($users);
}

Example 2 :-

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $search = "raj";
    
    $users = User::where('name', 'LIKE', "%{$search}%")
                ->latest()
                ->get();

    dd($users);
}

Example 3 :-

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $search = "raj";
    
    $users = User::where('name', 'LIKE','%' . $search . '%')
                ->latest()
                ->get();

    dd($users);
}

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook