I'm trying to retrieve Player with user and calendars - Player hasOne user and Player hasMany calendars.
But I need only male users - works fine, then I have to check calendars collision - select only players without calendar collision, query:
$freeplayers = Player::whereNotIn('id', $playersev)
->with('user','calendars')
->whereHas('user', function ($query) {
$query->where('gender', 'male');
})
->whereHas('calendars', function ($query) use ($event) {
$query->whereNotIn('fulldate', $event->fulldate);
})
->get();
Second whereHas is not working because:
- not every player has an event in calendar (so I cannot access to
fulldateattr) - player
hasManycalendars, so it is returned as another collection, I have to run->whereNotIn(...in every item of this calendars collection...
So, I need male players with empty calendar (they are available) and players without collision in their existing calendar.
How can I achieve that? I tried to combine ->doesntHave('calendars')->orWhereHas('cale... but it's not working because if user have calendar, it is returned as another collection...
Thanks
2017-11-10 16:00:00