【问题标题】:hasMany Relationship has not withTrashed()hasMany 关系没有 withTrashed()
【发布时间】: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

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    结束了目标模型没有使用 SoftDelete trait。

    固定。

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 2020-05-31
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      相关资源
      最近更新 更多