软删除laravel 5中表中的所有记录

Soft Delete all records from a table in laravel 5(软删除laravel 5中表中的所有记录)
本文介绍了软删除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中表中的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)