geekjeef/laravel-userstamps

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

dev-master 2020-12-30 00:00 UTC

This package is auto-updated.

Last update: 2024-09-12 16:08:08 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)。有关更多信息,请参阅许可证文件