ItSolutionStuff.com

Laravel Search Case Insensitive Query Example

By Hardik Savani • April 16, 2024
Laravel

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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Select Custom Column with Value in Laravel Query?

Read Now →

Laravel Eloquent Left Join Where Null Condition Example

Read Now →

PHP Laravel Left Join Query Example

Read Now →

Laravel Eloquent take() and skip() Query Example

Read Now →

Laravel Eloquent inRandomOrder() Method Example

Read Now →

Laravel Eloquent Order By Query Example

Read Now →

Laravel Eloquent orderByRaw() Query Example

Read Now →

Laravel Eloquent Where Query Examples

Read Now →

Laravel Eloquent orWhere() Condition Example

Read Now →

Laravel Eloquent WhereIn Query Example

Read Now →

Laravel Many to Many Eloquent Relationship Tutorial

Read Now →