Eloquent relationships laravel

我们两清 提交于 2020-05-19 03:59:27

问题


I have 3 tables

categories

  • id
  • name

categories_product

  • id
  • category_id
  • product_id

and a product table

products

  • id
  • name

I want products based on catergori_id, how kan i do that with laravel Eloquent?


回答1:


Simple as this:

Product::whereCategori_id($category)->get();


来源:https://stackoverflow.com/questions/26920372/eloquent-relationships-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!