mardi 1 décembre 2015

Laravel 5 - constraining by parent relations

Say I have a reservations table

id - restaurant_table_id - guest_id
1  - 3                   - 5
2  - 4                   - 7

And then an orders table

id - reservation_id - item_id
1  - 1                   - 2
2  - 2                   - 4

How can I pull orders that belong to a restaurant table?

I have tried:

$orders = ReservationOrders::with(['reservation' => function ($query) use ($restaurant_table_id) {
        $query->where('restaurant_table_id', $restaurant_table_id);
    }])
        ->get();

But the results included orders for all restaurant tables.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1XFN79c
via IFTTT

Aucun commentaire:

Enregistrer un commentaire