定制 oanhnn/laravel-fakeid 二次开发

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

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

oanhnn/laravel-fakeid

Composer 安装命令:

composer require oanhnn/laravel-fakeid

包简介

Using fake id on URL in Laravel application

README 文档

README

Build Status Coverage Status Latest Version Total Downloads Requires PHP Software License

Easy fake model ID on URL Laravel Application.

Requirements

  • php >=7.2
  • Laravel 7.0+

Laravel 5.5+ using version 1.x (require php 7.1.3+)

Installation

Begin by pulling in the package through Composer.

$ composer require oanhnn/laravel-fakeid

Publish config file with

$ php artisan vendor:publish --provider="Laravel\\FakeId\\ServiceProvider"

or

php artisan vendor:publish --tag=laravel-fakeid-config

Edit config/fakeid.php for config specific drivers.

Usage

Getting start

In your model class, add implement interface ShouldFakeId and a trait RoutesWithFakeId:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\FakeId\Contracts\ShouldFakeId;
use Laravel\FakeId\RoutesWithFakeId;

class MyModel extends Model implements ShouldFakeId
{
    use RoutesWithFakeId;
 
    // other logic
}

Using specific driver

By default, RoutesWithFakeId use default driver, it is set in config file. You can override getFakeIdDriver() method to use specific driver:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\FakeId\Contracts\ShouldFakeId;
use Laravel\FakeId\Contracts\Driver;
use Laravel\FakeId\Facades\FakeId;
use Laravel\FakeId\RoutesWithFakeId;

class MyModel extends Model implements ShouldFakeId
{
    use RoutesWithFakeId;

    /**
     * @return \Laravel\FakeId\Contracts\Driver
     */
    public function getFakeIdDriver() : Driver
    {
        return FakeId::driver('hex');
        // or create driver instance
        // return new HexDriver();
    }
}

Note With each drivers, the input data format may be different, but the output data after decode is same with input

Driver Input type Encoded type Decoded type
base64 string string string
hashids int[] string int[]
hex string string string
optimus int int int
prefix string string string
chain string string string

Custom driver

You can also create custom driver by implements Laravel\FakeId\Contracts\Driver interface

namespace App;

use Laravel\FakeId\Contracts\Driver;

class CustomDriver implements Driver
{
    // your driver logic
}    

And register with FakeId Manager by add below code to AppServiceProvider::boot() method

<?php

namespace App\Providers;

use App\CustomDriver;
use Illuminate\Support\ServiceProvider;
use Laravel\FakeId\Facades\FakeId;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        FakeId::extend('custom', function($app) {
            return new CustomDriver();
        });

        // other logic
    }
}

Now, you can use it

<?php

use Laravel\FakeId\Facades\FakeId;

FakeId::driver('custom')->encode('123');

Changelog

See all change logs in CHANGELOG

Testing

$ git clone git@github.com/oanhnn/laravel-fakeid.git /path
$ cd /path
$ composer install
$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email to Oanh Nguyen instead of using the issue tracker.

Credits

License

This project is released under the MIT License.
Copyright © Oanh Nguyen.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固