Laravel Eloquent Where Like Query Example Tutorial

By Hardik Savani April 16, 2024 Category : Laravel

Hi Guys,

Are you looking for an example of laravel eloquent where like query. If you have a question about laravel eloquent like query then I will give a simple example with a solution. you will learn laravel where like query . I explained simply about laravel like query example. Follow the below tutorial step of laravel where like query variable.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

Here, i will give you simple two example for sql like query in laravel. so let's see the simple sql query and Laravel Where with Like query.

SQL Example:

SELECT *

FROM `users`

WHERE `name` LIKE '%hard%';

Laravel Where Like Query Example 1:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\User;

class UserController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$search = 'hard';

$users = User::select("*")

->where('name','LIKE',"%{$search}%")

->get();

dd($users);

}

}

Laravel Where Like Query Example 2:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\User;

class UserController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$search = 'hard';

$users = User::select("*")

->where('name','LIKE','%'.$search.'%')

->get();

dd($users);

}

}

I hope it can help you...

Tags :
Shares