Friday, July 13, 2018

Laravel Case Sensitive Query

PHP Laravel is one of the popular PHP frameworks. It has many inbuilt functions to reduce developers efforts while developing projects. To perform case sensitive search in laravel, there is no inbuilt function provided as of Laravel 5.6. So, now how we do it ?.

user_table
id name
1 Eshin
2 Jozer
3 W3schools100

We have to use MySql function BINARY in where clause to perform case sensitive querying. The MySql example is,

SELECT * FROM 'user_table' WHERE BINARY 'username' = 'W3schools100';  

So how we do in Laravel
We have to add DB::raw() raw query to make case sensitive query. For example

DB::table('user_table')->where(DB::raw("BINARY `username`"),'W3schools100')->get();
or
DB::table('user_table')->whereRaw("BINARY `username` = 'W3schools100'")->get();

1 comment:

  1. Laravel Development Company, Get a free quote for laravel web development requirement from a leading Laravel Development Company. Discuss your web project with us to get large discounts...Contact us:+91-9806724185 or Contact@expresstechsoftwares.com

    ReplyDelete