Laravel Case Sensitive Query Search Example

By Hardik Savani August 14, 2021 Category : Laravel

Hi,

In this example, i will show you laravel case sensitive query. i explained simply step by step laravel where case sensitive query. i explained simply step by step laravel case sensitive search query. we will help you to give example of laravel case sensitive query with where condition. Let's see bellow example how to make case sensitive 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 sensitive name like if you search "Hardik" then it should only get that record. so that solution i will give you simple example and show you how to make case sensitive query using mysql BINARY in laravel. you can use this example in laravel 6, laravel 7, laravel 8 and laravel 9 version.

Let's see solution and check full example as bellow:

Solution:

$users = User::select("id", "name", "email")

->where(DB::raw('BINARY `name`'), "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('BINARY `name`'), "Hardik")

->get()

->toArray();

dd($users);

}

}

Output:

Array

(

[0] => Array

(

[id] => 1

[name] => Hardik

[email] => carri13@nhpc.us

)

)

I hope it can help you...

Tags :