【问题标题】:Method Illuminate\Database\Query\Builder::onlyTrashed does not exist方法 Illuminate\Database\Query\Builder::onlyTrashed 不存在
【发布时间】:2019-01-24 08:22:42
【问题描述】:

当我尝试在其中一个应用程序模型上使用软删除时,我得到 Method Illuminate\Database\Query\Builder::onlyTrashed 不存在异常。在用户模型上它正在工作。他们都使用 SoftDeletes trait。

【问题讨论】:

    标签: laravel eloquent soft-delete


    【解决方案1】:

    我忘记在模型的启动方法中调用 parent::boot()。我认为模型的构造函数也会出现同样的问题。

    public static function boot()
    {
        parent::boot(); //this was missing
    
        self::creating(function($model) {
            $event = self::orderBy('id', 'desc')->first();
            $model->identifier = $event ? ($event->identifier+1) : 1000;
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-24
      • 2019-10-04
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      相关资源
      最近更新 更多