Laravel 8 Where Like Query Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
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

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →