软删除laravel 5中表中的所有记录 [英] Soft Delete all records from a table in laravel 5

查看:32
本文介绍了软删除laravel 5中表中的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法软删除表中的所有现有行?我试过( Prospect::delete(); )它永久删除了所有行,但它在软删除中不起作用.

Is there any way to soft delete all the existing rows in a table? I have tried ( Prospect::delete(); ) it deleted all the rows permanently, But it doesn't work in soft deleting.

推荐答案

如果您使用的是 4.2 之前的 Laravel 框架,那么您可以将模型中的软删除设置为,

If you are using Laravel framework older than 4.2, then you can set the soft delete in your model as,

class ModelName extends Eloquent {
    protected $table = 'table_name';
    protected $softDelete = true;
}

如果您使用的是 Laravel 框架 4.2,那么您可以将模型中的软删除设置为,

If you are using Laravel framework 4.2, then you can set the soft delete in your model as,

use IlluminateDatabaseEloquentSoftDeletingTrait;
class ModelName extends Eloquent {
    use SoftDeletingTrait;
    protected $table = 'table_name';
}

如果您使用的是4.2以上的Laravel框架,那么您可以将模型中的软删除设置为,

If you are using Laravel framework above 4.2, then you can set the soft delete in your model as,

use IlluminateDatabaseEloquentSoftDeletes;
class ModelName extends Eloquent {
    use SoftDeletes;
    protected $table = 'table_name';
}

我希望你使用的是 Laravel 5.所以你可以使用第三种方法.

I hope you are using Laravel 5. So you can use the third method.

这篇关于软删除laravel 5中表中的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆