使用composer update更新到4.2后,我添加了
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
到用户模型。以下是使用此模型的代码:
$users = User::withTrashed()->paginate(20);
但是当我运行应用程序时,它会显示以下错误消息:
未定义的索引:用户 在\ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Eloquent \ Model.php 346
我试着换到
$users = User::all();
一切都很好。那么我怎么能解决这个问题呢?
这个问题可能是因为如果你有覆盖模型的构造函数但没有调用父元素。所以在你自己的模型的构造函数中添加parent::__constructor()
。此外,如果你设置静态boot
方法,@ Ash已经提到过,你还需要调用parent::boot()
。