MySQL value BETWEEN Two Columns in Laravel
Today, We are going to learn how to fine MySQL value BETWEEN Two Columns in Laravel. In one of my project, I need to find the value BETWEEN two columns and fetch the records. Laravel allows us to write raw query using DB::raw method.
MySQL BETWEEN Two Columns in Laravel
First of all, We are going to write the Laravel raw query for finding the MySQL value BETWEEN Two Columns.
Just follow the query for finding the number between two columns.
$items = Availability::whereRaw( \DB::raw(' 25 BETWEEN `from_no` AND `to_no` ') )->get();
Also, We can achieve the same result using less than or greater than like below.
$itemExits = Availability::where('from_no','<=',25) ->where('to_no','>=',25) ->get();
Both queries are working fine with Laravel for finding the MySQL value BETWEEN Two Columns in Laravel. Even you can use this query in core PHP. I hope the article is helpful to you.
If you face any issue after following the query please write the comment.