kerattila/laravel-track-author
最新稳定版本:v2.0.4
Composer 安装命令:
composer require kerattila/laravel-track-author
包简介
Extension to add created_by, updated_by and deleted_by columns to Eloquent models.
README 文档
README
This package allow you to track the user who created, deleted and deleted eloquent modelss.
Install and configure
You can install the package via composer:
composer require kerattila/laravel-track-author
Publish the config file by running:
php artisan vendor:publish --provider="Kerattila\TrackAuthor\TrackAuthorServiceProvider"
After publishing configuration file, adjust the values accordingly your needs:
<?php return [ 'models' => [ 'user' => \App\User::class ], 'columns' => [ 'createdByColumnName' => 'created_by', 'updatedByColumnName' => 'updated_by', 'deletedByColumnName' => 'deleted_by', ] ];
Model and migration configuration
Migrations:
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; Schema::table('posts', function (Blueprint $table) { // this will automatically add created_by, updated_by and updated_by nullable columns $table->trackAuthor(); });
Models
You can add the Kerattila\TrackAuthor\Traits\TrackAuthor trait to your models or just add one of the CreatedBy, UpdatedBy, DeletedBy traits.
Example:
<?php namespace App; // use Kerattila\TrackAuthor\Traits\CreatedBy; // use Kerattila\TrackAuthor\Traits\UpdatedBy; // use Kerattila\TrackAuthor\Traits\DeletedBy; use Kerattila\TrackAuthor\Traits\TrackAuthor; use Illuminate\Database\Eloquent\Model; class Post extends Model { use TrackAuthor; // use CreatedBy, UpdatedBy, DeletedBy; }
Relations
Relations are the type of BelongsTo and can be accessed as follows:
$post = \App\Post::find(1); $createdBy = $post->createdBy; $updatedBy = $post->updatedBy; $deletedBy = $post->deletedBy;
统计信息
- 总下载量: 1.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-21