Level 12
What about if you specify both column keys
return $this->hasManyThrough('App\Models\Manufacturer', 'App\Models\Product', column_from_product_table, column_from_manufacturer_table );
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have the next 3 tables
---Products
-id
-name
-category
-manufacturer
---Categories
-id
-name
---Manufacturers
-id
-name
In Category Model i want to make a relation to get all the manufacturers that products have in that category
i try with
return $this->hasManyThrough('App\Models\Manufacturer', 'App\Models\Product', 'category');
no success the he returns me wrong query
select `manufacturers`.*, `products`.`category` from `manufacturers` inner join `products` on `products`.`id` = `manufacturers`.`product_id` where `products`.`category` = 172
I need the next query:
select `manufacturers`.*, `products`.`category` from `manufacturers` inner join `products` on `products`.`manufacturer` = `manufacturers`.`id` where `products`.`category` = 172
Some idea?
Thank you
@crazydan This is not hasManyThrough. You can use belongsToMany with products being pivot table.
Please or to participate in this conversation.