markwalet / laravel-hashed-route
A Laravel package that replaces the default route model binding for a safer version.
Fund package maintenance!
markwalet
www.paypal.me/markwalet
Installs: 3 780
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 0
Open Issues: 1
Requires
- php: 8.*
- hashids/hashids: 3.*|4.*
- jenssegers/optimus: ^0.2.3
- laravel/framework: ~8.74|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: 4.*|5.*|6.*|7.*|8.*
- phpunit/phpunit: ~9.3
- dev-master
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-laravel-10-support
- dev-update-manager-dependencies
- dev-laravel-9-support
- dev-add-php-8-1-support
- dev-drop-php-7-3-support
- dev-upgrade-versions
- dev-laravel-8-support
This package is auto-updated.
Last update: 2024-11-06 21:26:09 UTC
README
A Laravel package that replaces the default route model binding for a safer version.
Installation
You can install this package with composer:
composer require markwalet/laravel-hashed-route
Laravel 5.5 uses Package auto-discovery, so you don't have to register the service provider. If you want to register the service provider manually, add the following line to your config/app.php
file:
MarkWalet\LaravelHashedRoute\HashedRouteServiceProvider::class
Usage
When you want to hash the routes for a given model. The only thing you have to is is adding the HasHashedRouteKey
trait:
use MarkWalet\LaravelHashedRoute\Concerns\HasHashedRouteKey; class TestModel extends Model { use HasHashedRouteKey; //... }
After that you can use the model like you normally would. Because the trait overrides the resolveRouteBinding()
and getRouteKey()
methods, no extra changes are required to your code.
You do have to change your code when you are building your urls by manually getting the $model->id
property from your model. Then you will have to change those calls to $model->getRouteKey()
.
Configuration
The default configuration is defined in hashed-route.php
. If you want to edit this file you can copy it to your config folder by using the following command:
php artisan vendor:publish --provider="MarkWalet\LaravelHashedRoute\HashedRouteServiceProvider"
In this file you can configure different codecs for the encoding and decoding of keys, as well as setting a default configuration.
You can override this configuration by setting the codec
property on your model.
The supported codec drivers are: null
, hashids
, optimus
& base64
. Use the null
driver if you want to disable route key hashing.