jeudi 27 juin 2019

Laravel With() relation querying - condition to main table

I need to query a nested relation using 'with' construction, but I have no idea how to use main table's fields in relation condition. Example:

Order::with([
    'products',
    'statuses' => function($statuses) {
        $statuses->where('id', LAST_STATUS_ID_FROM_ORDERS_TABLE);
    }
])->get()

Any suggestions?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire