A am creating a calendar application with laravel as API.
I want to be able to search through activities (Activity model) and filter the months. So I have a search term and an array of certain months to filter by. This array looks like this:
array (
0 =>
array (
'first_date' => '2016-03-11',
'last_date' => '2016-03-31',
),
1 =>
array (
'first_date' => '2016-04-01',
'last_date' => '2016-04-30',
),
2 =>
array (
'first_date' => '2016-05-01',
'last_date' => '2016-05-31',
)
// etc...
)
An Activity has multiple CalendarItem(s) which represents the dates of an Activity.
Now I am not really sure what would be the best approach to get the Activity models between the dates of that array.
- I can raw query the CalendarItems and retrieve the Activities via their eloquent relationship, then I would have to sort out the duplicates.
- I can use whereHas('CalendarItem', function($q){ $q->whereBetween(etc..)})
Does anyone have a good suggestion?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire