assumilhig/laravel-key-generator 问题修复 & 功能扩展

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

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

assumilhig/laravel-key-generator

Composer 安装命令:

composer require assumilhig/laravel-key-generator

包简介

A laravel package that generate a eloquent model keys

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Installation

You can install the package via composer:

composer require assumilhig/laravel-key-generator

You can publish everything with:

php artisan vendor:publish --provider="Assumilhig\LaravelKeyGenerator\LaravelKeyGeneratorServiceProvider"

This is the contents of the published config file:

return [
    'length' => 20
];

Usage

There are two available methods to generate the key:

Using the Laravel Key Generator

LaravelKeyGenerator::generate(
    prefix: 'test', // what you want to prefix your keys with.
    length: 20, // optional - the default of 20 is set in the config.
)

Using the Str Key

Illuminate\Support\Str::Key(
    prefix: 'test', // what you want to prefix your keys with.
    length: 20, // optional - the default of 20 is set in the config.
)

Eloquent Integration

There is an eloquent model trait available to use called HasKey which will:

namespace App\Models;

use Assumilhig\LaravelKeyGenerator\HasKey;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    use HasKey;
    use HasFactory;

    public $timestamps = false;

    protected $fillable = [
      'key'
    ];
}

When you are creating an eloquent model, the trait will be booted. It will get the first 3 characters of the Model name, force them to lowercase and append a "_" and use this as the prefix for the Key Factory

An example:

Category Model: cat_N6mU3u0aTgktLQnAsxwU

Currently this isn't a configured option as it is easy to override or implement yourself.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email asumi0198@gmail.com instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固