There are now 2 tables goods and products {code ...} first, go to the goods table to query the merchant_id5 product. Because the product name and more detailed information are not changed in the goods table, we need to cycle the data queried in the goods table... there are now 2 tables
Goods and products
$products = Goods::where('merchant_id','=','5')->get(); foreach($products as $p){ print_r($p->product_id); $_name = Product::where('id','=',$p->product_id)->get(); $_name = $_name[0];}
First, go to the goods table to query the products with merchant_id = 5;
Because there is no change to the product name and more detailed information in the goods table;
Therefore, you need to use the product_id field of the goods table to query more information (name) matched by the id field of products in the goods table.
How can I query it?
Now I want to add the queried name to the $ products object loop.
Can you give me some guidance (* ^__ ^ ......
Reply content:
There are now 2 tables
Goods and products
$products = Goods::where('merchant_id','=','5')->get(); foreach($products as $p){ print_r($p->product_id); $_name = Product::where('id','=',$p->product_id)->get(); $_name = $_name[0];}
First, go to the goods table to query the products with merchant_id = 5;
Because there is no change to the product name and more detailed information in the goods table;
Therefore, you need to use the product_id field of the goods table to query more information (name) matched by the id field of products in the goods table.
How can I query it?
Now I want to add the queried name to the $ products object loop.
Can you give me some guidance (* ^__ ^ ......
php
Class Goods extends Model {public function product () {return $ this-> belonsto ('app \ products') ;}}$ Products = Goods: with ('product ') -> where ('Merchant _ id', '=', '5')-> get (); // the product in the array is the product_id information of the goods table corresponding to products.