vendredi 20 novembre 2015

Laravel 5.1 How to get all models and related models by querying a related model?

Model Relationships... Apartment has many Floorplan. Apartment has many Photo. Floorplan has many FloorplanImage.

I want to get all Apartment that have a Floorplan with 0 bedrooms. ALSO, I want to grab the related Photo, and related FloorplanImage.

My somewhat useless code...

    $apartmentsWithStudios = Floorplan::with(['apartment', 'floorplanImage'])
                                        ->where('bedrooms', '=', 0)->get();

How do I grab the Apartment and all related models from querying the Floorplan model? Is it possible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire