Skip to content
Advertisement

Laravel: Joining tables in Laravel and loop on the other tables

I am joining 3 tables, property, facilities, and images. A property has many facilities and has many images.

On my query its looping the same property how many times it has facilities and images and each loop is getting 1 facility and 1 image. What I need to accomplish is it will loop per property and will get all facilities and images a property has.

JavaScript

Property Model

JavaScript

Facility Model

JavaScript

Image Model

JavaScript

Blade

JavaScript

Advertisement

Answer

you can eager load your relation:

JavaScript

in blade you may do something like:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement