robjbrain / laravel-user-timestamps
用于替换 UserTimestamps 和 SoftDeletes 的插件,同时存储认证用户的 ID。
dev-master
2022-06-23 09:07 UTC
Requires
- php: >7.1.0
This package is auto-updated.
Last update: 2024-09-23 13:57:39 UTC
README
这是一个用于替换 Laravel 中 HasTimestamps 特性的插件。它将添加额外的字段,即执行操作的用户 created_by_id 和 updated_by_id。
它还支持多态关系,这将添加 created_by_type 和 updated_by_type 字段。
它还支持 SoftDeletes,用于替换 Laravel 内置的 SoftDeletes 特性,包括执行软删除的用户 deleted_by_id。
安装
您可以通过 composer 安装此包
composer require robjbrain/laravel-user-timestamps
使用方法
将 CacheMutationsTrait 特性添加到您想要缓存变动的模型中。
use Robjbrain\LaravelUserTimestamps\HasUserTimestamps; use Robjbrain\LaravelUserTimestamps\UserSoftDeletes; class YourEloquentModel extends Model { use HasUserTimestamps; use UserSoftDeletes; // This will behave the same UserTimestamps public $timestamps = true; // This will utilise the updated_by_id and created_by_id fields public $userTimestamps = true; // This will utilise the updated_by_type and created_by_type fields public $polymorphicTimestamps = true; // This will utilise the deleted_by_id field public $userSoftDeletes = true; // This will utilise the deleted_by_type field public $polymorphicSoftDeletes = true; }
如果您使用 $polymorphicTimestamps,则无需设置 $userTimestamps 或 $timestamps 为 true。
如果您使用 $userTimestamps,则无需设置 $timestamps 为 true。