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


基础教程推荐
- 将变量从树枝传递给 js 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的PDF导出 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01