承接 limanweb/eloquent-extensions 相关项目开发

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

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

limanweb/eloquent-extensions

最新稳定版本:v1.2.1

Composer 安装命令:

composer require limanweb/eloquent-extensions

包简介

Extensions for Laravel Eloquent\Model

README 文档

README

Extensions for Laravel Eloquent\Model and other classes

  • Trait HasUserstamps for filling userstamp fields created_at, updated_at, deleted_at by authorized user ID

Installation

Run:

composer require "limanweb/eloquent-extension"

Package contents

  • /Models
    • /Concerns
      • HasUsertimestamps.php - trait for userstamps filling in model
      • HasCompositePrimaryKey.php - trait for using in model composite primary key
      • HasBuilderConfigurator - draft of trait to build queries with request params

Usage

HasUserstamps

Add into create or update table migration fields for userstamps created_at, updated_at and deleted_at. For examle modify CreateUsersTable migration.

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            ...
            // add userstamps fields
            $table->bigInteger('created_by')->nullable();
            $table->bigInteger('updated_by')->nullable();
            // if SoftDeletes trait will be used in model then add deleted_by field
            // $table->bigInteger('deleted_by')->nullable();
              
        });
    }

    ...

}

In the model you must:

  1. declare using of trait Limanweb\EloquentExt\Models\Concerns\HasUserstamps
  2. use HasUserstamps trait in the model
  3. enable userstamps by define public property $userstamps with true value
...

use Limanweb\EloquentExt\Models\Concerns\HasUserstamps;  // (1) declare

class User extends Authenticatable
{
    use Notifiable;
    use HasUserstamps;          // (2) use trait in the model
    
    public $userstamps = true;  // (3) enable userstamps

    ...
}

The created_by and updated_by fields in your model will now be populated in the same way as the timestamp fields when you create and update the model. If your model uses SoftDeletes traite, will also be processed field, deleted_by.

HasCompositePrimaryKey

In the model you must:

  1. declare using of trait Limanweb\EloquentExt\Models\Concerns\HasCompositePrimaryKey
  2. use HasCompositePrimaryKey trait in the model
  3. set $incrementing model property as false
  4. set $primaryKey model property as array complex primary key part names
...

use Limanweb\EloquentExt\Models\Concerns\HasCompositePrimaryKey;  // (1) declare trait

class Example extends Model
{

    use HasCompositePrimaryKey;         // (2) use trait in the model
    
    public $incrementing = false;			// (3)
    
    protected $primaryKey = ['part1', 'part2']; // (4)

    ...
}

Example of using

>>> $m = Example::find([65, 275]);
=> App\Example {#3837
     part1: 65,
     part2: 275,
     message: "record 65:275",
   }

>>> $m->getKey();
=> [
     65,
     275,
   ]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-04