Skip to content

Automatic route ID obfuscation in routes for Laravel 5

License

Notifications You must be signed in to change notification settings

javaftper/Laravel-FakeId

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel FakeID

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads License

Enables automatic Eloquent model ID obfuscation in routes using Optimus.

Installation

  1. In the require key of composer.json file add the following

    "propaganistas/laravel-fakeid": "~1.0"
  2. Run the Composer update command

    composer update
  3. In your app config, add the Service Provider to the end of the $providers array

    Laravel 5

    'providers' => [
       App\Providers\EventServiceProvider::class,
       App\Providers\RouteServiceProvider::class,
       ...
       Propaganistas\LaravelFakeId\FakeIdServiceProvider::class,
    ],
  4. Run the following artisan command to auto-initialize the package's settings

    php artisan fakeid:setup

Usage

First of all, make sure the model is bound to Laravel's Router, e.g. by inserting this on top of the routes.php file:

Route::model('mymodel', 'App\MyModel');

This way you can reference a placeholder in your routes (edit/{mymodel})

Next, simply import Propaganistas\LaravelFakeId\FakeIdTrait into your model:

use Illuminate\Database\Eloquent\Model;
use Propaganistas\LaravalFakeId\FakeIdTrait;

class MyModel extends Model {

  use FakeIdTrait;

}

All routes generated for this model will now automatically contain obfuscated IDs and incoming requests to {mymodel} routes will be handled correctly.

Notice

This package features a slightly modified version of Laravel's built-in Illuminate\Routing\Router class and injects it into the IoC container. If you are using a custom Router of your own, you can publish the config file to disable FakeId's Router. Please note that in this case you need to decode incoming requests containing obfuscated IDs yourself.

FAQ

Why didn't you implement Hashids instead of Optimus?

Simple: speed! Optimus is based on Knuth's multiplicative hashing method and proves to be quite faster than Hashids. It's even mentioned on Hashids' own website.

About

Automatic route ID obfuscation in routes for Laravel 5

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%