【发布时间】:2019-06-04 23:10:12
【问题描述】:
我在 StackOverflow 上看到了一个类似问题的答案:https://stackoverflow.com/a/40654005/1055279
我看到了
public function order() {
return $this->belongsToMany('Order')->withTrashed();
}
在我的场景中,我有 Customer 具有 n Devices 的模型
// Relation 1 to n from Customer model to Device model
public function devices()
{
return $this->hasMany('App\Device')->withTrashed();
}
注意我添加了 withTrashed,因为我总是需要检索 softDeleted 数据。
问题
从我得到的客户模型中检索设备
消息:“调用未定义的方法 Illuminate\Database\Eloquent\Relations\HasMany::withTrashed()"
可能我使用了错误的语法。我是来寻求帮助的。
- Laravel 是 @5.8.19
- PHP 是 @7.2.x
【问题讨论】: