我制作了两个表库存和Inventory_images。 Inventory表的主键是inventory_images表的外键,现在我试图获取同一库存的所有图片但出现错误。 这里是我的代码不在laravel中工作的外键关系
库存模型:
/**
* The table name that should be hidden from other modules
*/
protected $table = 'inventories';
protected $PrimaryKey = 'id';
public function test(){
return $this->belongsTo('App\InventoryImage', 'i_id');
}
InventoryImage型号:
protected $table = 'inventory_images';
protected $PrimaryKey = 'id';
public function inv_det(){
return $this->belongsTo('App\Inventory', 'id');
}
控制器:
$inventory = Inventory::with('test')->orderBy('id', 'DESC')->paginate('10');
dd($inventory);
能有人请帮我找出问题
有什么错误? – Nima
调用模型[App \ Inventory]上的未定义关系[测试]。 这是错误 – Mohsin