我有一個雄辯的問題,當我打電話時,$unit->assets我收到一個空集合。但是,如果我打電話給我$unit->assets()->get()-我收到的集合具有正確的結果。根據文檔,我的關系定義正確,考慮到調用get()關系對象時得到正確的結果,這似乎也很明顯。class Unit extends Model{ protected $table = 'organisation_units'; public function assets() { return $this->hasMany(MediaElement::class, 'owner_id'); }}class MediaElement extends Model{ protected $table = 'template_elements'; public function owner() { return $this->belongsTo(Unit::class, 'owner_id'); }}表結構是Organisation_unitsid | 名稱template_elementsid | owner_id | 名稱| 文件名
- 1 回答
- 0 關注
- 151 瀏覽
添加回答
舉報
0/150
提交
取消