首页 » 技术分享 » Call to undefined method Illuminate\Database\Query\Builder::trashed()

Call to undefined method Illuminate\Database\Query\Builder::trashed()

 

今天在使用laravel软删除的时候,一直报Call to undefined method Illuminate\Database\Query\Builder::trashed()的错误,查看数据库发现数据被删除了(不是软删除),查看了手册后,发现在模型中没有开启软删除(尴尬…),在模型中添加use SoftDeletes;即可。

<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Package extends Model
{
    use SoftDeletes; // 开启软删除

    protected $table = 'packages';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
       'name', 'cover', 'user_id'
    ];

    public $timestamps = true;
    protected $dates = ['delete_at'];
}

转载自原文链接, 如需删除请联系管理员。

原文链接:Call to undefined method Illuminate\Database\Query\Builder::trashed(),转载请注明来源!

0