【发布时间】:2016-02-29 02:08:27
【问题描述】:
我有两张桌子:
products: id, name, manufacturer
myproducts:id, user_id, product_id
我通过我的身份验证令牌知道 user_id。使用此 user_id 令牌,想从 myproducts 中获取 product_id 和 id,然后查询 products 表以获取 mymproducts 中的 product_id 与 products 表中的 id 匹配的名称和制造商。目标是为用户提供一个可编辑的列表,他/她可以在 myproducts 表中进行编辑。
到目前为止,我只能做到
$productlist = DB:table('myproducts')->where('user_id', $userid)->get();
这将返回用户拥有的所有产品。但我无法加入表格以返回用户拥有的每个产品的产品数据。
有什么建议吗?
伪代码:
Select * from myproducts wheer user_id = $userid
对于每个产品 -> 获取产品名称和制造商,其中 id 等于 product_id
【问题讨论】:
标签: mysql laravel join laravel-5.1