codiliateur/eloquent-model-userstamps 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

codiliateur/eloquent-model-userstamps

最新稳定版本:v1.0.5

Composer 安装命令:

composer require codiliateur/eloquent-model-userstamps

包简介

This package provides an Eloquent model trait to automatically maintain user stamps in columns (created_by, updated_by, deleted_by) of your model.

README 文档

README

Installing

This package can be installed using composer:

composer require codiliateur/eloquent-model-userstamps

Model trait

Add trait Codiliateur\Userstamps\Models\HasUserstamps into your model.

class YourModel extends Model
{
    use Codiliateur\Userstamps\Models\HasUserstamps;
    ...
}    

To customize userstamp column names, define constants CREATED_BY, UPDATED_BY, DELETED_BY in your specific model.

class YourModel extends Model
{
    use Codiliateur\Userstamps\Models\HasUserstamps;
    ...
    
    const CREATED_BY = 'creator_id';
    const UPDATED_BY = 'updater_id';
    const DELETED_BY = 'liquidator_id';
    
    ...
}    

Migration helpers

This package automatically adds into Blueprint two helper methods userstamps() and dropUserstamps()

    // to add user stamp columns
    userstamps(bool $softDeletes = false, string $columnType = null, array $columnNames = null)

    // to drop user stamp columns
    dropUserstamps(bool $softDeletes = false, array $columnNames = null)

To add userstamp columns into your table add lines into up() of your migration.

For model without SoftDeleting trait

$table->userstamps();

or the same with first argument

$table->userstamps(false);  // the same

And for model that used SoftDeleting trait

$table->userstamps(true);

By default, added columns have bigInteger type.

To change column type, you can put smallInteger, integer, bigInteger or uuid into second argument $columnType. For example:

$table->userstamps(false, 'uuid');

To customize column names, you can put array of names into third argument $columnNames.

    $table->userstamps(false, null, [
        'creator_id',    // [0] instead of 'created_by'
        'updater_id',    // [1] instead of 'updated_by'
        'liquidator_id', // [2] instead of 'deleted_by'
    ]);

Don't forget add any arguments into dropUserstams() call.

Configuring package

By default, for userstamp columns used names created_by, updated_by and deleted_by and these columns are type bigInteger. These column names and column type defined in package configuration file.

You can publish this configuration file into yor project. For this run command:

php artisan vendor:publish --provider="Codiliateur\Userstamps\UserstampsServiceProvider"

File .\config\codiliateur\userstamps.php will be published.

To change userstamp column's type use config option column_type.

For example:

'column_type' => 'uuid', // if user ID has 'uuid' type

There you can use smallInteger, integer, bigInteger, uuid values.

To change default userstamp column's names you must modify config option columns.

For example:

    'columns' => [
        'creator_id',    // [0] instead of 'created_by'
        'updater_id',    // [1] instead of 'updated_by'
        'liquidator_id', // [2] instead of 'deleted_by'
    ],

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固