dimanche 9 décembre 2018

Laravel collection with multiple date filter with or operator

I'm trying to filter several items from a Collection in Laravel 5.7. The items have a startdate and an (optional) enddate.

The filter i'm trying to create is the following.

startdate <= now() AND

( enddate >= now() OR enddate = '' OR enddate = NULL )

I've tried the following but it doesn't work:

$this->items->where([  
  ['startdate', '<=', date('Y-m-d'))],
  ['enddate', '>=', date('Y-m-d')]
])->orWhere([
  ['startdate', '<=', date('Y-m-d'))],
  ['enddate', '=', '']
])->orWhere([
  ['startdate', '<=', date('Y-m-d'))],
  ['enddate', '=', null]
]);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire