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

查看:92
本文介绍了从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 Framework 4.2,则可以在模型中将软删除设置为

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

use Illuminate\Database\Eloquent\SoftDeletingTrait;
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 Illuminate\Database\Eloquent\SoftDeletes;
class ModelName extends Eloquent {
    use SoftDeletes;
    protected $table = 'table_name';
}

我希望您正在使用Laravel5.因此,您可以使用第三种方法.

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

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

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