首页 > 解决方案 > hasMany 关系没有 withTrashed()

问题描述

我在 StackOverflow 上看到了类似问题的答案:https ://stackoverflow.com/a/406540​​05/1055279

我在这里看到

public function order() {
     return $this->belongsToMany('Order')->withTrashed();
 }

在我的场景中,我的Customer模型具有n Device s

// 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()”

可能我使用了错误的语法。我是来寻求善意的帮助的。

标签: laravellaravel-5

解决方案


结束目标模型使用 SoftDelete 特征。

固定的。


推荐阅读