alihann / laravel-rockid
Laravel package for id obfuscation using jenssegers/optimus.
v1.0
2016-06-01 17:30 UTC
Requires
- php: ^5.5.9 || ^7.0
- illuminate/console: 5.2.*
- illuminate/support: 5.2.*
- jenssegers/optimus: ~0.2
- phpseclib/phpseclib: ^2.0
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
-
composer require
composer require alihann/laravel-rockid
-
in your config/app.php
'providers' => [ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, ... Alihann\LaravelRockid\RockidServiceProvider::class, ],
-
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, ],
-
publish the config file
php artisan vendor:publish
-
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); }); }