mardi 19 mars 2019

Eloquent query to select rows that between two dates , two columns of dates (hotel room search)

I am trying to get rows that lie between two dates such

from and to dates should lie between start_date and end_date of the table.

the table structure is

id | hotel_code | room_code | start_date |  end_date  | price | 
1  |    10      |     20    | 2019-04-01 | 2019-05-31 |  100  |
1  |    10      |     20    | 2019-06-01 | 2019-08-31 |  150  |

have tried with different methods little confused and getting no valid response.

Finally, the following one looks fine,

->where('start_date','<=',$from)
->where('end_date','>=',$from)
->where('start_date','<=',$to)
->where('end_date','>=',$to)


Can it be simplified in any way using Laravel Eloquent?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire