sqits / laravel-userstamps
添加 created_by, updated_by 和 deleted_by 字段到模型中的包。
0.0.12
2024-03-18 11:01 UTC
Requires
- php: ^7.4|^8.0
- laravel/framework: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- doctrine/dbal: ^3.5
- larapack/dd: ^1.1
- orchestra/testbench: ^7.19
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-18 11:56:49 UTC
README
提供一个 Eloquent 特性,可以自动在模型上维护 created_by、updated_by 和 deleted_by(当使用 softDeletes 时)字段,由当前登录的用户执行。
安装和用法
此包需要 PHP 7.2 和 Laravel 5.6 或更高版本。在您的控制台中运行以下命令来安装包;
composer require sqits/laravel-userstamps
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Sqits\UserStamps\UserStampsServiceProvider" --tag="config"
这是发布后的配置文件内容
return [ /* * Define the table which is used in the database to retrieve the users */ 'users_table' => 'users', /* * Define the table column type which is used in the table schema for * the id of the user * * Options: increments, bigIncrements, uuid * Default: bigIncrements */ 'users_table_column_type' => 'bigIncrements', /* * Define the name of the column which is used in the foreign key reference * to the id of the user */ 'users_table_column_id_name' => 'id', /* * Define the mmodel which is used for the relationships on your models */ 'users_model' => \App\Models\User::class, /* * Define the column which is used in the database to save the user's id * which created the model. */ 'created_by_column' => 'created_by', /* * Define the column which is used in the database to save the user's id * which updated the model. */ 'updated_by_column' => 'updated_by', /* * Define the column which is used in the database to save the user's id * which deleted the model. */ 'deleted_by_column' => 'deleted_by', ];
将宏添加到您的模型迁移中
public function up() { Schema::create('table_name', function (Blueprint $table) { ... $table->userstamps(); $table->softUserstamps(); }); }
将特性添加到您的模型中
use Sqits\UserStamps\Concerns\HasUserStamps; class Example extends Model { use HasUserStamps; }
将提供方法来检索执行创建、更新或删除操作的用户对象
$model->author; // the user who created the model $model->editor; // the user who last updated the model $model->destroyer; // the user who deleted the model
变更日志
有关最近更改的更多信息,请参阅变更日志。
安全性
如果您发现任何安全相关的问题,请通过info@sqits.nl发送电子邮件,而不是使用问题跟踪器。
致谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。