laravel - hasMany 关系没有 withTrashed()
问题描述
我在 StackOverflow 上看到了类似问题的答案:https ://stackoverflow.com/a/40654005/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()”
可能我使用了错误的语法。我是来寻求善意的帮助的。
- Laravel 是@5.8.19
- PHP 是@7.2.x
解决方案
结束目标模型未使用 SoftDelete 特征。
固定的。
推荐阅读
- javascript - 覆盖嵌套打字稿界面中的属性
- c# - C# 将列表输出到 Winforms 上的 DataGridView 或 ListView
- c - 兼容的结构类型
- elasticsearch - 支持不区分大小写搜索的 Elasticsearch 模板
- xamarin.forms - 使用 Xamarin Forms 应用程序中的图像打印 html
- android-studio - Flutter项目导入Android studio
- python - Numpy数组索引/分配问题,看起来应该可以工作的代码,不
- python - 带有 sympy 的变量的微分方程变化
- java - 插件定义的 JAXB 编组/解组对象
- html - “data-v-”是什么意思?