Hi, You might want to use Eager Loading https://laravel.com/docs/5.8/eloquent-relationships#eager-loading
Did you try that before?
Hello, I'm refactoring an old e-commerce site from plain PHP to Laravel 5.5. I have a list of products by categories and subcategories, which need to be filtered by brands.
I have an opportunities table which depends on products table which is related to a brands table, too.
Tables have foreign keys and relations are working fine when lazy loading queries. So, If I call something like {{ $opportunity->product->brand->name }} it displays correct brand name.
Actually my sql query to obtain all pertinent brands in a given list, is such as:
SELECT brands.id, brands.name from brands join products on products.brand_id = brands.id join opportunities on opportunities.`product_id` = products.id where opportunities.`status`=1 GROUP BY brands.name
This query is working as expected, but I wish to recode it in an eloquent style, so I need your help. Thank you in advance.
Please or to participate in this conversation.