jeudi 27 septembre 2018

In Laravels Eloquent, how do I get records with relationship?

I am trying to pull all records that have an event relationship which has an event date of today. I have the following code:

    EventStaffStation::with([
        'event' => function($query) {
            $query->where('event_date', Carbon::now()->format('d-m-Y'));
        }
    ])->where([
        'staff_id' => auth()->user()->id
    ])->has('event')->get()

This gives me a record event_staff_stations but it sets the event relationship to null. I want the record to not be returned if the relationship is null.

Basically if event_staff_station record isn't for today then I don't want it returned. I'm only interested in records with an event day of today.

Any help is appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire