承接 constant-null/eloquent-changed-by-user 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

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 Auth facade and expects it to implement Illuminate\Contracts\Auth\Guard contract

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固