michaeljmeadows/created-by
最新稳定版本:v2.1.0
Composer 安装命令:
composer require michaeljmeadows/created-by
包简介
A simple trait to add User relationships to Eloquent models to track creation, updating, and deletion.
README 文档
README
A simple trait to add User relationships to Eloquent models to track creation, updating, and deletion.
Installation
You can install the package via composer:
composer require michaeljmeadows/created-by
Usage
Assuming you already have a users table, add the following fields to the model migration:
$table->foreignId('created_by')->nullable()->constrained('users'); $table->foreignId('updated_by')->nullable()->constrained('users'); $table->foreignId('deleted_by')->nullable()->constrained('users');
If you're using UUID or ULID ID fields, replace foreignId in the above with foreignUuid or foreignUlid fields accordingly
Once the fields are added to the model, you can simply include the trait in your model's definition:
<?php namespace App\Models; use michaeljmeadows\Traits\CreatedBy; use Illuminate\Database\Eloquent\Model; class NewModel extends Model { use CreatedBy;
BelongsTo relationships to the User will now be accessible on your model:
$creator = $newModel->createdBy; $updater = $newModel->updatedBy; $deleter = $newModel->deletedBy;
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-07