我刚刚从Laravel 4.1更新到4.2.7。我试图使用以下方法删除软删除:
use SoftDeletingTrait; protected $dates = ['deleted_at'];
但这会给出错误' Not Found SoftDeletingTrait Class'。这个错误的原因是什么?
答案 0 :(得分:10)
只需按类型调用此方法,使用Illuminate \ Database \ Eloquent \ SoftDeletingTrait;'
use Illuminate\Database\Eloquent\SoftDeletingTrait; class User extends Eloquent { use SoftDeletingTrait; protected $dates = ['deleted_at']; }
=>或者< =
转到config / app.php&添加别名
对于laravel 4
'SoftDeletingTrait' => 'Illuminate\Database\Eloquent\SoftDeletingTrait',
对于Laravel 5
'SoftDeletes' => 'Illuminate\Database\Eloquent\SoftDeletes::class'; or use on model or controller file use Illuminate\Database\Eloquent\SoftDeletes;
答案 1 :(得分:4)
如果您使用的是laravel 5.1,则必须使用以下内容,
use Illuminate\Database\Eloquent\SoftDeletes;
不是
use Illuminate\Database\Eloquent\SoftDeletingTrait;
答案 2 :(得分:3)
卸下:
use Illuminate\Database\Eloquent\SoftDeletingTrait;
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
添加:
protected $softDelete = true;
答案 3 :(得分:0)
将此添加到模型中。
/bin/bash