jeanlrnt / laravel-cancellable
为 Laravel Eloquent 模型提供可取消特性的包
1.3
2023-09-13 15:21 UTC
Requires
- php: ^7.3|^8.0
- illuminate/database: ^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- illuminate/pagination: ^7.0|^8.0|^9.0|^10.0
- orchestra/testbench: ^6.3|^7.0|^8.0
- phpunit/phpunit: ^8.4|^9.1
This package is auto-updated.
Last update: 2024-09-13 17:17:10 UTC
README
一个简单的包,用于使 Laravel Eloquent 模型具有“可取消”特性。此包通过创建各种宏,以便在方法链中使用,使得取消模型变得简单。
安装
此包需要 PHP 7.3 或更高版本,以及 Laravel 6.0 或更高版本。
您可以通过 composer 安装此包
composer require jeanlrnt/laravel-cancellable
用法
迁移
Cancellable 特性与 Laravel 的 SoftDeletes 特性类似。此包还附带了一个有用的宏,用于 Laravel 的 \Illuminate\Database\Schema\Blueprint。要开始使用,只需将 cancelledAt 宏添加到迁移中,如下所示
Schema::create('posts', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('user_id'); $table->string('title'); $table->timestamps(); $table->cancelledAt(); // Macro });
Eloquent
现在,您可以安全地将 Cancellable 特性包含到您的 Eloquent 模型中
namespace App\Models; use \Illuminate\Database\Eloquent\Model; use \LaravelCancellable\Cancellable; class Post extends Model { use Cancellable; ... }
扩展
此特性提供的扩展包括:cancel、unCancel、withCancelled、withoutCancelled、onlyCancelled,可相应使用
$user = User::first(); $user->cancel(); $user->unCancel(); $usersWithCanceled = User::query()->withCanceled(); $onlyCanceledUsers = User::query()->onlyCanceled();
默认情况下,此特性的全局作用域在特性添加到模型时使用 withoutCanceled 扩展。
测试
composer test
变更日志
有关最近变更的详细信息,请参阅 CHANGELOG。
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 contact@jeanlaurent.fr 联系我们,而不是使用问题跟踪器。
致谢
许可协议
MIT 许可协议(MIT)。有关更多信息,请参阅 许可文件。
Laravel 包模板
此包是用 Laravel 包模板 生成的。