Apply the same logic for eager loading.
https://laravel.com/docs/9.x/eloquent-relationships#constraining-eager-loads
Is it somehow possible to eager load only matching records? My query looks like so
EventParticipant::with(['user', 'events'])
->whereHas('events', function ($query) {
$query->where('replay_vimeo_id', '<>', null)
->where('ends_at', '<', Carbon::now());
})
->whereExists(function ($query) {
$query->from('event_event_participant')
->where('created_at', '>', 'events.ends_at')
//->where('replay_email_sent', false)
;
})
->get();
What I want now is to eager load only the events where this matches
->whereHas('events', function ($query) {
$query->where('replay_vimeo_id', '<>', null)
->where('ends_at', '<', Carbon::now());
})
->whereExists(function ($query) {
$query->from('event_event_participant')
->where('created_at', '>', 'events.ends_at')
//->where('replay_email_sent', false)
;
Maybe someone can help
Please or to participate in this conversation.