ahuseiny / laravel-userstamps

一个简单的Laravel包,用于Eloquent模型用户特定字段。

v3.0.3 2020-12-30 00:00 UTC

This package is not auto-updated.

Last update: 2024-09-24 08:40:59 UTC


README

Laravel Userstamps是一个简单的Laravel包,用于你的Eloquent模型用户特定字段。此包自动在你的表上插入/更新创建者、最后更新者和删除记录的用户ID。

安装

  1. 在composer.json中添加仓库
"repositories": [
   {
     "url": "https://github.com/hrshadhin/laravel-userstamps.git",

      "type": "git"
    }
 ],
  1. composer.json的require部分添加包名
    • 对于Laravel 5.x,使用v1.0.1
     "hrshadhin/laravel-userstamps": "^1.0.0"
    
    • 对于Laravel 6.x,使用masterv2.0.1
     "hrshadhin/laravel-userstamps": "^2.0.0"
    
    • 对于Laravel 7.x,使用masterv3.0.0
     "hrshadhin/laravel-userstamps": "^3.0.0"
    

用法

使用userstamps()蓝图宏更新你的模型迁移,并添加created_byupdated_bydeleted_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)。请参阅许可证文件获取更多信息。