承接 tailflow/laravel-human-readable-keys 相关项目开发

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

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

tailflow/laravel-human-readable-keys

最新稳定版本:1.0

Composer 安装命令:

composer require tailflow/laravel-human-readable-keys

包简介

Generate Stripe-like IDs for Eloquent models

README 文档

README

Latest Version on Packagist Build Status on Github Actions

Have you ever wanted to generate Stripe-like IDs for your Eloquent models? This package does exactly that!

Installation

You can install the package via composer:

composer require tailflow/laravel-human-readable-keys

Usage

  1. Change type of the id (or whatever your primary key column is) to string in the migration
Schema::create('users', function (Blueprint $table) {
    $table->string('id');
    
    ...
});
  1. Add HasHumanReadableKey trait to a model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Tailflow\HumanReadableKeys\Concerns\HasHumanReadableKey;

class User extends Model
{
    use HasHumanReadableKey;

   ...
}
  1. (Optional) Customize key prefix and length

By default, a singular form of the table name is used as prefix for generated keys. You can customize that by overriding the getKeyPrefix method on the model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Tailflow\HumanReadableKeys\Concerns\HasHumanReadableKey;

class User extends Model
{
    use HasHumanReadableKey;

   ...
   
    public function getKeyPrefix(): string
    {
        return 'account';
    }
}

Generated keys contain a unique hash that is 24 characters in length. To customize hash length, override the getKeyLength method:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Tailflow\HumanReadableKeys\Concerns\HasHumanReadableKey;

class User extends Model
{
    use HasHumanReadableKey;

   ...
   
    public function getKeyLength(): string
    {
        return 16;
    }
}

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-04