【发布时间】:2015-01-30 15:06:36
【问题描述】:
有 3 种型号:
Products belongstoMany Categories
Products belongstoMany Stores
Categories belongstoMany Products
Stores belongstoMany Products
如何找到属于特定类别和特定商店的所有产品?
这是我尝试过的:
Product::getAll()->join('categorie_product', 'categorie_product.product_id', '=', 'product.id')
->join('categorie', 'categorie.id', '=', 'categorie_product.categorie_id')
->where('categorie.name', '=', $categorieName)
->paginate(10);
有什么建议吗?谢谢..
P.S.:我想用 eloquent 来完成这个任务。 DB::* 可以,但我需要雄辩的实现,因为我使用 Dingo API 来完成一些 REST API。
【问题讨论】:
标签: php laravel laravel-4 many-to-many eloquent