How to make string case-sensitive through Laravel query?

In our past post we have explained that How to integrate Guest checkout feature in Angular 5. This time its for integrating coupon code in Laravel.

If you are building a online shopping website and adding feature like coupon code then there will be need where you need to check and make sure that string (Letters) of coupon code are case sensitive.

So if you are searching for “How to make coupon code letters case sensitive in Laravel?” then it will be a perfect post for you.

There are two ways to make coupon code case sensitive.

Approach 1:

You can make particular column case sensitive using laravel schema builder with code mentioned below :

——————-Lets assume ‘CODE’ is column of table ‘Coupon’————————–


So by doing above, you can make your MySQL table column as case sensitive and it will match exact string.

Approach 2:

Personally, i love this method and applied few times. We know that any character have its own binary number system in 0,1 format. For example, letter “A” have its unique binary number and “a” have another unique binary number. So logic is, that if we will match the string with their associated binary number then it will be unique. Code for that in laravel with where clause is given below:

$couponcode = 'test123';
Coupon::where(DB::raw('BINARY `code`'),$couponcode)

Hope this article will be helpful for you. Enjoy! HAPPY CODING 😊

In case of any issues or implementation errors, you can get in touch with us. We are leading Laravel developers in UK and USA.

In London, we are providing our Laravel development services in England, London, South East, North of England, Midlands, South West,Wales and Scotland.

In USA, we are providing our Laravel development services in Atlanta, Boston, Chicago, Dallas, Houston, Los Angeles, Miami and New York, NY.

So if you want to hire best Laravel developer for your new project or existing issues then drop us a line.