There is a car dealers listing with pagination where I need to show first 3 cars with that car's manufacturer and model no of that dealer. Its like
Car Dealer 1
Car Dealer 2
and so on with pagination
Its obvious that querying in loop is not a good solution. Is there any good work around this problem?
I have checked hasManyThrough but it does not suits here.
its kind a query : get first 3 cars with manufacturer and model nos for each dealers in resultset. If Laravel relationship does not work then what queries should be used to avoid looping? Thanks
You want to eager load the cars and their properties.
Dealer::with(['cars', 'cars.models', 'cars.makes'])->get();
Now you can iterate as much as you need to. The query counts won't increase.
Sorry for short answer. On phone :)