私は2つのテーブルInventoriesとInventory_imagesを作成しました。インベントリテーブルのプライマリキーは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