dimanche 22 juillet 2018

How to write Laravel Eloquent whereBetween method with two columns

I am trying to write the following query in eloquent format :

SELECT * FROM `table_name` where timestamp_col1 AND timestamp_col2 BETWEEN 
'2018-07-23 11:45:25' and '2018-07-23 14:45:25'

By using default method from eloquent i was able to write the query in following format :

$this->getEntity()
     ->whereBetween('timestamp_col1', [$start, $end])
     ->orWhereBetween('timestamp_col2', [$start, $end])
     ->get();

But disadvantage of writing in above format is that i have to manually specify start and end timestamp individually for both columns. Is there any other way to achieve this or do i have to use whereRaw() method



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire