gavinz8/swoft-soft-delete

Swoft/SoftDelete 组件,适用于 swoft 框架

1.0.1 2020-05-25 09:42 UTC

This package is auto-updated.

Last update: 2024-09-26 10:44:55 UTC


README

Swoft/SoftDelete 组件,适用于 swoft 框架

安装

  • 使用 composer 安装
composer require gavinz8/swoft-soft-delete

配置

  • 在 config/base.php 中配置
<?php
return [
    'name'  => 'Swoft framework 2.0',
    'debug' => env('SWOFT_DEBUG', 1),
    'soft_delete' => [
        'column' => 'deleted_at',
        'ignore' => ['migration']
    ]
];

-- 列表配置:您想要标记为删除的列名。 -- 忽略配置:您想要不使用软删除的表。

如何使用

  • 您可以直接使用模型或 db 方法删除,如下所示
User::where('id', 1)->delete();
DB:table('user')->where('id', 1)->delete();
  • 然后您可以使用任何想要的方法获取数据,即使是对多个表进行查询,如下所示
User::find(1);
User::where('id', 1)->first();
User::where('id', 1)->get();
Db::from('user a u')->join('role as r', u.id, r.user_id)->where('u.id', 1)->get();

许可证

该组件是开源软件,许可协议为Apache 许可证