Laravel Case Sensitive Query Search Example
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, 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('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...
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
- PHP Laravel Inner Join Query Example
- Laravel Eloquent whereNotNull() Query Example
- Laravel Eloquent orderByRaw() Query Example
- Laravel Eloquent Where Query Examples
- Laravel Eloquent orWhere() Condition Example
- Laravel Select with Sum Query Example
- How to Get Query Strings Value in Laravel?
- Laravel Query Builder Where Exists Example
- Example of unionAll in Query Builder Laravel
- Laravel Join with Subquery in Query Builder Example