skip to Main Content

Laravel find if number is between two different fields in a MySQL Database

Laravel find the number is between two different fields. Many times we find the record between two dates ‘from’ to ‘to’ date right. But how to find a number of between two fields. So it’s too easy in Laravel. So let’s see how to write `DB RAW` query in Laravel for find number between two fields.

Just used below simple query.

$itemExits = Availability::whereDate('status','=','1')
    	->whereRaw(\DB::raw(' 25 BETWEEN `from_no` AND `to_no` '));
$result = $itemExits->get();

As per above query, we get to record like greater than ‘from_no’ and lower than ‘to_no’ records from the database.

we can write two separate conditions for the getting same records like below.

$itemExits = Availability::whereDate('status','=','1')
$result = $itemExits->get();

We get the same result as above query both query return the same result.

If you face any issue after using the above query please write the comment below.


I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top