constant-null/eloquent-changed-by-user
Composer 安装命令:
composer require constant-null/eloquent-changed-by-user
包简介
This simple trait written for eloquent allows you to automaticly write down id of last user changed the database record.
README 文档
README
Please be aware that this trait uses
Authfacade and expects it to implementIlluminate\Contracts\Auth\Guardcontract
How it works
Quite simple actually, just before saving row to database, this trait gets id of current user using Auth::user()->id (thats why requirements above exists) and write it to specified database field (for more specifics read the Installation and configuration section)
Installation and configuration
This trait can be installed via composer. Just add following to your composer.json file:
{
"require": {
"constant-null/eloquent-changed-by": "~0.1"
}
}
and then run:
$ composer update
To start using this trait you need to import it to Eloquent model
<?php use ConstantNull\Eloquent\Support\ChangedByUser; use Illuminate\Database\Eloquent\Model; class SomeModel extends Model { use ChangedByUser; /* The rest of the your class */ }
and add column to database in which user id will be stored. Like this for example:
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class BestMigrationEver extends Migration { public function up() { Schema::table('some_table', function(Blueprint $table) { $table->integer('changed_by')->nullable(); }); }
How you can see in example the default column name for user id is changed_by, but it can be easily changed by specifying constant CHANGED_BY in your class body.
For example i want this column name to be 'last_user_id':
<?php use ConstantNull\Eloquent\Support\ChangedByUser; use Illuminate\Database\Eloquent\Model; class SomeModel extends Model { use ChangedByUser; const CHANGED_BY = 'last_user_id'; /* Rest part of the your class */ }
Thats all!
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-08