Laravel 7/6 Where Like Query Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

272

02-01-2020


Hii Guys,

In this example,I will learn you how to use where like query in laravel 7/6.you can simply and easy to define where like query in laravel 7/6.

Laravel 7/6 provide query builder and mysql like condition is very simple to use.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);

}

It will help you...


Recommended Posts