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.

<?php
$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.

<?php
$itemExits = Availability::whereDate('status','=','1')
    	->where('from_no','>=',25)
        ->where('to_no','<=',25);
$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.