ahuseiny / laravel-userstamps
一个简单的Laravel包,用于Eloquent模型用户特定字段。
v3.0.3
2020-12-30 00:00 UTC
Requires
- php: ^8.0
- illuminate/database: ^9.0
- illuminate/support: ^9.0
README
Laravel Userstamps是一个简单的Laravel包,用于你的Eloquent模型用户特定字段。此包自动在你的表上插入/更新创建者、最后更新者和删除记录的用户ID。
安装
- 在composer.json中添加仓库
"repositories": [
{
"url": "https://github.com/hrshadhin/laravel-userstamps.git",
"type": "git"
}
],
- 在
composer.json
的require部分添加包名- 对于Laravel 5.x,使用v1.0.1
"hrshadhin/laravel-userstamps": "^1.0.0"
- 对于Laravel 6.x,使用
master
或v2.0.1
"hrshadhin/laravel-userstamps": "^2.0.0"
- 对于Laravel 7.x,使用
master
或v3.0.0
"hrshadhin/laravel-userstamps": "^3.0.0"
用法
使用userstamps()
蓝图宏更新你的模型迁移,并添加created_by
、updated_by
和deleted_by
字段。
Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name', 100); $table->userstamps(); $table->timestamps(); });
然后在你的模型上使用UserstampsTrait
。
namespace App; use Hrshadhin\Userstamps\UserstampsTrait; class User extends Model { use UserstampsTrait; }
删除列
你可以使用dropUserstamps()
方法删除可审计的列。
Schema::create('users', function (Blueprint $table) { $table->dropUserstamps(); });
这样就完成了!
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。