Example for raw query of between operator. Let’s suppose you have a following records with dates classification, and would like to fetch where current date fits in between start_date and end_date:
+---------------------+----------- | id | start_date | end_date | +---------------------+-----------+ | 1 | 2020-01-10 | 2020-20-15| | 2 | 2020-08-01 | 2020-08-31| | 3 | 2020-09-01 | 2020-09-10| +------+--------------+-----------+
Query would be as following:
$now = Carbon::now(); $records = DB::table('table_name') ->whereRaw('"'.$now.'" between `start_date` and `end_date`') ->get();