Laravel Search Case Insensitive Query Example
In this tutorial, you will learn laravel case insensitive query. it's simple example of laravel where case insensitive query. you will learn laravel case insensitive search query. if you want to see example of laravel case insensitive query with where condition then you are a right place. You just need to some step to done how to make case insensitive query in laravel query builder.
Sometime we have records in users table with following name like "Hardik", "HARDIK" and "hardik". now you just need to get case insensitive name like if you search "Hardik" then it should get all records even if it's in uppercase, lowercase or capitalize. so that solution i will give you simple example and show you how to make case insensitive query using mysql lower in laravel. you can use this example in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.
Let's see solution and check full example as bellow:
Solution:
$users = User::select("id", "name", "email")
->where(DB::raw('lower(name)'), strtolower("Hardik"))
->get();
Example
users table:
Controller Code:
<?php
namespace App\Http\Controllers;
use App\Models\User;
use DB;
class ITSController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$users = User::select("id", "name", "email")
->where(DB::raw('lower(name)'), strtolower("Hardik"))
->get()
->toArray();
dd($users);
}
}
Output:
Array
(
[0] => Array
(
[id] => 1
[name] => Hardik
[email] => carri13@nhpc.us
)
[1] => Array
(
[id] => 3
[name] => HARDIK
[email] => aatmaninfotech1sdsd@gmail.co
)
[2] => Array
(
[id] => 4
[name] => hardik
[email] => fanny.baumbach@example.org
)
)
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Select Custom Column with Value in Laravel Query?
- Laravel Eloquent Left Join Where Null Condition Example
- PHP Laravel Left Join Query Example
- Laravel Eloquent take() and skip() Query Example
- Laravel Eloquent inRandomOrder() Method Example
- Laravel Eloquent Order By Query Example
- Laravel Eloquent orderByRaw() Query Example
- Laravel Eloquent Where Query Examples
- Laravel Eloquent orWhere() Condition Example
- Laravel Eloquent WhereIn Query Example
- Laravel Many to Many Eloquent Relationship Tutorial