Package Data | |
---|---|
Maintainer Username: | mrynk |
Maintainer Contact: | michel@mrynk.nl (Michel Ypma) |
Package Create Date: | 2013-09-05 |
Package Last Update: | 2014-03-04 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-26 15:12:34 |
Package Statistics | |
---|---|
Total Downloads: | 355 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 0 |
A Laravel 4 package for the official hashids library
Add mrynk\l4-hashids
as a requirement to composer.json:
{
"require": {
"mrynk/l4-hashids": "master"
}
}
Update your packages with composer update
or install with composer install
.
Once Composer has installed or updated your packages you need to register Hashids with Laravel itself. Open up app/config/app.php and find the providers key towards the bottom and add:
'Mrynk\L4Hashids\L4HashidsServiceProvider'
L4-Hashids's configuration file can be extended by creating app/config/packages/mrynk/l4-hashids/config.php
. You can find the default configuration file at vendor/mrynk/l4-hashids/src/config/config.php.
You can quickly publish a configuration file by running the following Artisan command.
$ php artisan config:publish mrynk/l4-hashids
You can use Hashids to obfuscate your url id's.
Use it in your controller like:
public function myAction( $pHash )
{
$id = Hashids::decrypt( $pHash );
Model::find( reset( $id ) );
}
Since v2.0 you can define different setting groups. Obviously default is the default group. To use another you can explicitly tell so:
Use it in your controller like:
public function myAction( $pHash )
{
$id = Hashids::make('groupname')->decrypt( $pHash );
Model::find( reset( $id ) );
}
A more cleaner way would be to use it in your route model binding
Route::bind('user', function( $value, $route )
{
if( $result = User::find( Hashids::decrypt( $value ) ) )
return $result;
throw new NotFoundException;
});