alihann / laravel-rockid by alihann

Laravel package for id obfuscation using jenssegers/optimus.
20
1
1
Package Data
Maintainer Username: alihann
Maintainer Contact: le3han@gmail.com (Ali Han)
Package Create Date: 2016-06-01
Package Last Update: 2016-06-01
Language: PHP
License: MIT
Last Refreshed: 2024-11-11 15:07:04
Package Statistics
Total Downloads: 20
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel Rockid

Id obfuscation for Laravel using Optimus.

How to Install

  1. composer require

    composer require alihann/laravel-rockid
    
  2. in your config/app.php

    'providers' => [
            App\Providers\EventServiceProvider::class,
            App\Providers\RouteServiceProvider::class,
            ...
            Alihann\LaravelRockid\RockidServiceProvider::class,
        ],
    
  3. and if you want to use facade

    'aliases' => [
            'Validator' => Illuminate\Support\Facades\Validator::class,
            'View' => Illuminate\Support\Facades\View::class,
            ...
            'Rockid' => Alihann\LaravelRockid\Facades\Rockid::class,
        ],
    
  4. publish the config file

    php artisan vendor:publish
    
  5. generate numbers and add to the published config file. (i.e. config/rockid.php)

    php artisan rockid:generate
    

Usage

you can use ObfuscatesId trait to get the obfuscated id of the model in your views.

use Illuminate\Database\Eloquent\Model;
use Alihann\LaravalRockId\ObfuscatesId;

class User extends Model {

  use ObfuscatesId;

}

now you have getId method in your model to generate an obfuscated id.

<a href="user/{{ $user->getId() }}">Show user</a>

routes.php

Route::bind('user', function ($value) {
    $id = Rockid::decode($value);
    return \App\User::find($id);
});

Route::get('user/{user}', function ($user) {
    return $user->getId();
});

or in RouteServiceProvider class

public function boot(Router $router)
{
    parent::boot($router);

    $router->bind('user', function ($value) {
        $id = app('rockid')->decode($value);
        return \App\User::find($id);
    });
}