tobidsn/laravel-userstamps

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

v5.0.1 2022-08-06 00:00 UTC

This package is auto-updated.

Last update: 2024-09-17 19:34:08 UTC


README

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

安装

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

      "type": "git"
    }
 ],
  1. 在require中添加包名,dev后跟分支名
"tobidsn/laravel-userstamps": "dev-master"

用法

更新模型迁移并使用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 Tobidsn\Userstamps\UserstampsTrait;

class User extends Model
{
    use UserstampsTrait;
}

删除列

您可以使用dropUserstamps()方法删除可审计的列。

Schema::create('users', function (Blueprint $table) {
    $table->dropUserstamps();
});

原始地址:https://github.com/hrshadhin/laravel-userstamps

完成!

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件