alihann/laravel-rockid

Laravel package for id obfuscation using jenssegers/optimus.

v1.0 2016-06-01 17:30 UTC

This package is not auto-updated.

Last update: 2024-11-04 13:57:10 UTC


README

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);
    });
}