我正在尝试使用单个基类来抽象我的模型。我有三个继承自同一基础的模型:
- 修复
- 检查
- 购买
我能够成功创建模型并将其持久保存到数据库中,但是在获取时我得到一个空白屏幕,没有抛出任何错误。当我删除 $with
属性时,一切似乎都有效。
代码如下:
abstract class ItemType extends Model
{
public $timestamps = false;
protected $with = ['details'];
public function details()
{
return $this->morphOne(Item::class, 'type', 'item_details_type', 'item_details_id', 'id');
}
}
class Repair extends ItemType
{
protected $table = 'repairs';
protected $guarded = ['id', 'created_at', 'updated_at'];
protected $morphClass = self::class;
}
class Inspection extends ItemType {}
class Purchase extends ItemType {}
最佳答案
最后我决定使用没有抽象类的morphTo
关系来解决这个问题。
关于php - Laravel Eloquent 'with' 数组正在中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34141635/