定制 monurakkaya/laravel-unique-code-generator 二次开发

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

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

monurakkaya/laravel-unique-code-generator

Composer 安装命令:

composer require monurakkaya/laravel-unique-code-generator

包简介

Provides unique code for your models

README 文档

README

Provides unique code for your Eloquent models

INSTALLATION

composer require monurakkaya/laravel-unique-code-generator

USAGE

The schema

To create the column

// This will generate an unique string column named `code` 255 length which equivalent to $table->string('code', 255)->unique();
Schema::create('table', function (Blueprint $table) {
    ...
    $table->uniqueCode();
});

To drop the column

Schema::table('table', function (Blueprint $table) {
    $table->dropUniqueCode();
});

To use your own column just pass the parameters to override the default values

// on create
$table->uniqueCode('my_code', 'bigInteger', 32); // columnName, columnType, columnLength

// on drop
$table->dropUniqueCode('my_code');

Using schema helper is optional. You can go on with your own definitions.

The model

Your model should use Monurakkaya\Lucg\HasUniqueCode trait to enable unique code functions:

use Monurakkaya\Lucg\HasUniqueCode;

class Foo extends Model {
    use HasUniqueCode;
}

and that's all.

$foo = Foo::create(['title' => 'Foo']);
#attributes: array:10 [▼
    "id" => 1
    "code" => "OF0EIL8B"
    "title" => "Foo"
    "created_at" => "2022-01-24 13:11:03"
    "updated_at" => "2022-01-24 13:11:03"
  ]

SETTINGS

To change the column name just override the uniqueCodeColumnName method on your model


class Foo extends Model {
    use HasUniqueCode;
    
    protected static function uniqueCodeColumnName()
    {
        return 'my_code';
    }
}

** Make sure your code column name to be equal to your column name. Default is code

To change the code type just override the uniqueCodeType method on your model


class Foo extends Model {
    use HasUniqueCode;
    
    protected static function uniqueCodeType()
    {
        return 'numeric';
    }
}

Available types are 'random_uppercase', 'random_lowercase', 'uuid', 'numeric'. Default is random_uppercase

** If you are going to use uuid, I recommend you to set column definition as uuid

To change the code length just override the uniqueCodeLength method on your model


class Foo extends Model {
    use HasUniqueCode;
    
    protected static function uniqueCodeLength()
    {
        return 32;
    }
}

** Make sure your code length lte than column length. Default is 8

Tests

To run the tests, execute the following from the command line, while in the project root directory:

./vendor/bin/phpunit

monurakkaya/laravel-unique-code-generator 适用场景与选型建议

monurakkaya/laravel-unique-code-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.91k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2022 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「model」 「code generator」 「laravel」 「eloquent」 「laravel unique code」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 monurakkaya/laravel-unique-code-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 monurakkaya/laravel-unique-code-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 monurakkaya/laravel-unique-code-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-24