berthott/laravel-userstamps

Laravel 用户时间戳助手

3.0.0 2023-02-16 10:03 UTC

This package is auto-updated.

Last update: 2024-09-26 10:56:41 UTC


README

这是一个用于维护 Laravel 中用户时间戳的助手。通过向模型添加特质,轻松添加和维护用户时间戳。

安装

$ composer require berthott/laravel-userstamps

用法

  • 创建您的表和相应的模型,例如使用 php artisan make:model YourModel -m
  • 在迁移中添加 $table->userstamps()
    • 如果您的模型上使用了 SoftDeletes 特质,另外添加 $table->softDeletesUserstamp()
  • HasUserstamps 特质添加到您新创建的模型中。
  • 有关更多宏,请参阅 \berthott\Userstamps\UserstampsServiceProvider::register()
  • 提供方便的 creator()editor()destroyer()

选项

您可以通过将这些常量添加到模型中来更改列名。

const CREATED_BY = 'alt_created_by';
const UPDATED_BY = 'alt_updated_by';
const DELETED_BY = 'alt_deleted_by';

注意,在这种情况下,您不能使用 $table->userstamps(),但需要使用以下方式分别定义列:

$table->unsignedBigInteger('alt_created_by')->nullable();
$table->unsignedBigInteger('alt_updated_by')->nullable();
$table->unsignedBigInteger('alt_deleted_by')->nullable();

兼容性

已测试与 Laravel 10.x 兼容。

致谢

受到 https://github.com/WildsideUK/Laravel-Userstampshttps://github.com/hrshadhin/laravel-userstamps 的启发。

许可证

请参阅许可证文件。版权 © 2023 Jan Bladt。