Table of Contents
Inside this article we will see how to execute case sensitive query in laravel 8. Case sensitive simply means the keyword should match exact with the pattern.
Laravel 8 run case sensitive query is very interesting tutorial to see and super easy to implement. If query doesn’t have any idea about matching exact pattern i.e case sensitivity then it normally returns the data set when it matches only with no case.
Example – India, india, INDIA will be same if no case sensitive matches. But India is not equals to india if we need case sensitive too.
Case Sensitive Means,
Case Insensitive Means,
To add the concept of case sensitive query pattern in laravel 8 we will use the concept of mysql Binary.
Learn More –
- How To Work with Session Timeout in Laravel 8
- How to Work with Telescope In Laravel 8 Tutorial
- Jetstream Login Register Email Verification in Laravel 8
- JQuery Ajax Form Validation in Laravel 8 Tutorial
Let’s get started.
Installation of Laravel Application
Laravel Installation can be done in two ways.
- Laravel Installer
- By using composer
To install Laravel via Laravel installer, we need to install it’s installer first. We need to make use of composer for that.
composer global require laravel/installer
This command will install laravel installer at system. This installation is at global scope, so you type command from any directory at terminal. To verify type the given command –
This command will open a command palette of Laravel Installer.
To create ad install laravel project in system,
laravel new blog
With the name of blog a laravel project will be created at your specified path.
By using composer
Alternatively, we can also install Laravel by Composer command create-project. If your system doesn’t has Composer Installed, Learn Composer Installation Steps. Here is the complete command to create a laravel project-
composer create-project --prefer-dist laravel/laravel blog
After following these steps we can install a Laravel application into system.
To start the development server of Laravel –
php artisan serve
This command outputs –
Starting Laravel development server: http://127.0.0.1:8000
Assuming laravel already installed at system.
Laravel 8 Case Insensitive Query
Suppose, we have a database table called “countries”. Inside this table we have countries rows.
Let’s take an example row from that.
Query to select Afghanistan row from table –
$country_info = Country::select("id", "sortname", "phonecode") ->where("name", "Afghanistan") ->get() ->toArray(); OR $country_info = Country::select("id", "sortname", "phonecode") ->where("name", "afghanistan") ->get() ->toArray();
Inside this query where no case matching –
where("name", "Afghanistan") Equals To where("name", "afghanistan")
It returns the same output –
Laravel 8 Case Sensitive Query
In this case, we will add the concept of mysql binary which matches the exact keyword with case sensitive too.
$country_info = Country::select("id", "sortname", "phonecode") ->where(Country::raw("BINARY name"), "Afghanistan") ->get() ->toArray();
We have used mysql binary here – Country::raw(“BINARY name”). When we run it returns
Afghanistan Not Equals To afghanistan
If we change query a bit like this –
->where(Country::raw("BINARY name"), "afghanistan")
It returns –
We hope this article helped you to learn Laravel 8 Run Case Sensitive Query Tutorial in a very detailed way.
Find More on Laravel 8 Articles here
- How to Create Multi Language Website in Laravel 8
- How To Read XML File in Laravel 8 – Example
- How To Upload And Save XML Data in Laravel 8
- Laravel 8 Ajax Post Request Tutorial
- Laravel 8 Authentication using Jetstream with Inertia Js
- Laravel 8 Authentication using Jetstream with Livewire
- Laravel 8 Authentication with Breeze Tutorial
- Laravel 8 Clear Cache of Route, View & Config
- Laravel 8 Cron Job Task Scheduling Tutorial
- Laravel 8 DataTable Ajax Pagination with Search And Sort
- Laravel 8 Firebase Push Notification Tutorial
- Laravel 8 Form Validation Methods
- Laravel 8 Installation Guide – PHP Framework
- Laravel 8 Layouts And Views Complete Guide
- Laravel 8 Routing Tutorial Step by Step Guide
- Laravel 8 Send Mail using Gmail SMTP Server
- Laravel 8 Send Push Notification to Android Using Firebase
- Laravel 8 Send Push Notification to IOS Using Firebase
- Laravel 8 Stub Customization