我有 3 个安装了外键的表。
customers {customer_id, customer_name}
products {product_id, product_name}
customer_products {id, customer_id (foreignkey), product_id (foreignkey)}
我的控制器代码:
$CustomerProducts = ModelName::where('customer_id', 'somevalue')
->Join('customer_products', 'product_id', '=', 'customer_id')
->get();
我的型号代码:
class ModelName extends Model {
protected $table = 'hd_products';
public $primaryKey = 'id'; }
我的代码有什么问题,因为我得到了错误的结果。我想展示客户信息及其相关产品。
互换的青春
汪汪一只猫