定制 sysbox/laravel-base-entity 二次开发

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

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

sysbox/laravel-base-entity

Composer 安装命令:

composer require sysbox/laravel-base-entity

包简介

A base model for non-numerical id and common attributes: id, active, created, created_at, updated, updated_at

README 文档

README

This package provides the base model for laravel models with 6 key fields:

  • id ( non numeric / non incremental )
  • active ( boolean )
  • created_by_id ( the id of the creator )
  • created_at ( the timestamp of the creating )
  • updated_by_id ( the id of the updater )
  • updated_at ( the timestamp of the updating )

Installation

Via Composer

$ composer require sysbox/laravel-base-entity

Setup

###step 1 Publish the config file

$ php artisan vendor:publish --provider='Sysbox\LaravelBaseEntity\LaravelBaseEntityServiceProvider'

###step 2 Setup your laravel's interface model, like below: edit <laravel-root-dir>/app/User.php

class User extend BaseModel implements UserReferable <<<<<<<<< implement this interface
{

    /**
     * @return mixed <<<<<<<<< add this function
     */
    public function getUserId()
    {
        return $this->id;
    }

    /**
     * @return \Illuminate\Contracts\Auth\Authenticatable|UserReferable|null
     */
    public static function getCurrentUser() <<<<<<<<< add this function
    {
        return Auth::user();
    }
}

###step 3 Setup your config file: edit <laravel-root-dir>/config/LaravelBaseEntity.php, you will see something like:

return [


    // this is the user class that will be refer to for fields: created_by_id and updated_by_id
    'user_class' => User::class, <<<<<<<<< add user class here.

    // this is the system user's id,
    // leave it BLANK for auto generation.
    // or specifiy in env, ie: 'system_user_id' => env('SYSTEM_USER_ID'),
    'system_user_id' => '',
];

Usage

Now you should be able to create any Laravel Model and just extend from BaseModel, like this

use Sysbox\LaravelBaseEntity\BaseModel;
class Person extend BaseModel <<<<<<<<< extend your BaseModel
{
    // all other laravel function for the model..
}

And you can also create columns in migration, like this:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Sysbox\LaravelBaseEntity\Facades\LaravelBaseEntity;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            LaravelBaseEntity::addBasicLaravelBaseEntityColumns($table);
            $table->string('name');
            //or add column
            // LaravelBaseEntity::addHashIdColumn($table, 'another_user_id');
        });
    }

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固