jaacu / laravel-model-hashids
Requires
- php: ^7.1
- illuminate/support: 5.8.*
- vinkla/hashids: ^6.0
Requires (Dev)
- graham-campbell/analyzer: ^2.1
- graham-campbell/testbench: ^5.2
- phpunit/phpunit: ^7.0
Provides
- vinkla/hashids: ^6.0
This package is auto-updated.
Last update: 2024-10-18 13:32:32 UTC
README
Compatible with laravel version 5.8.x
This package allows you to use hashids in your models using the vinkla/laravel-hashids package
This package includes the vinkla/laravel-hashids package
Installation
You can install the package via composer:
composer require jaacu/laravel-model-hashids
Usage
Add to your model migration the following code
... $table->hashid(); ...
Then simply add the UsesHashIds trait to your model
use Jaacu\LaravelModelHashids\Traits\UsesHashIds; class MyModel extends Model { use UsesHashIds; }
Now using default laravel routing implicint binding will use the hashid insted of the normal id
Examples
A model using the trait UsesHashIds
$model = Model::first();
Generating url
route('model.show',$model); // output: http://mydomain/model/<hashid>
Getting the hashid
$model->getId() // returns: the model <hashid>
Config
Publish the config file to change default behavior
php artisan vendor:publish --provider="Jaacu\LaravelModelHashids\LaravelModelHashidsServiceProvider"
By default the generated hashid follows this structure: app name + model name + model id hash
- app name is set by the app.config name and can be overwritten by setting a new 'short_name' in the config/app.php file
- model name is set by the model class name
- model hash id is set by the model 'id' hash
This package shares the config file from vinkla/laravel-hashids
In the config/hashids.php you can set the hash length and salt.
'connections' => [ 'main' => [ 'salt' => env('APP_KEY'), // Uses the env app key by default 'length' => 6, ], 'alternative' => [ 'salt' => 'your-salt-string', 'length' => 'your-length-integer', ], ]
Docs
For more info on the hash functionality see vinkla/laravel-hashids
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email jaacu.97@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.