定制 arkitecht/laravel-attributions 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arkitecht/laravel-attributions

最新稳定版本:5.2

Composer 安装命令:

composer require arkitecht/laravel-attributions

包简介

Laravel 5/6/7/8/9/10 - Track attributions (model creator / updater)

README 文档

README

Laravel 5.1 Source License

Easily attribute the creator / last updater of a model in your database.

Designed to work like (and alongside) $table->timestamps() in your Laravel migrations, Attributions introduces $table->attributions(). This will add creator_id and updater_id columns to your table to track the user that created and updated the model respectively. By default this uses the Laravel 5.1 predefined users table, but can be customized to reference any table and key combination.

Quick Installation

You can install the package most easily through composer

Laravel 5.1.x

composer require arkitecht/laravel-attributions

Schema Blueprint and Facades

Once this operation is complete, you can update the Schema Facade to point to our drop-in replacement, which uses our Blueprint extension class to add the attributions.

Laravel 5.1.x

Facade (in config/app.php)

'Schema' => Illuminate\Support\Facades\Schema::class,

'Schema' => Arkitecht\Attributions\Facades\Schema::class,

You can also manually use the attributions builder, without overwriting the Facade like so:

use Arkitecht\Attributions\Database\Schema\Blueprint;

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    $schema =  DB::getSchemaBuilder();

    $schema->blueprintResolver(function($table, $callback) {
        return new Blueprint($table, $callback);
    });

    $schema->create('tests', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();
        $table->attributions();
    });
}

Using it in your migrations

To have your migration add the attribution columns, just call the Blueprint::attributions method.

class CreateTestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tests', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->attributions();
        });
    }
	
	...

}

You can also have it reference an alternate table (from users) or key (from id).

class CreateTestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tests', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->attributions('employees','employee_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('tests');
    }
}

Using it in your model

To have the creator and updater automagically updated when a model is created and updated, just use the Attributions trait in your model.

<?php

namespace App;

use Arkitecht\Attributions\Traits\Attributions;
use Illuminate\Database\Eloquent\Model;

class Test extends Model
{
    use Attributions;
}
?>

统计信息

  • 总下载量: 13.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固