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-12-19 03:07:23 |
Package Statistics | |
---|---|
Total Downloads: | 20 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Id obfuscation for Laravel using Optimus.
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
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);
});
}