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

2022-01-02 00:00:00 model php mysql laravel-5 controller

有没有办法软删除表中的所有现有行?我试过( 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.

相关文章