https://github.com/markwalet/laravel-hashed-route
A Laravel package that replaces the default route model binding for a safer version.
https://github.com/markwalet/laravel-hashed-route
laravel php php-library security
Last synced: 3 months ago
JSON representation
A Laravel package that replaces the default route model binding for a safer version.
- Host: GitHub
- URL: https://github.com/markwalet/laravel-hashed-route
- Owner: markwalet
- License: mit
- Created: 2017-11-29T15:00:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-06T18:15:37.000Z (almost 2 years ago)
- Last Synced: 2024-09-14T12:27:05.435Z (10 months ago)
- Topics: laravel, php, php-library, security
- Language: PHP
- Size: 113 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
[](http://github.com/markwalet/laravel-hashed-route)
[](LICENSE.md)
[](https://packagist.org/packages/markwalet/laravel-hashed-route)
[](https://github.com/markwalet/laravel-hashed-route/actions)
[](https://codecov.io/gh/markwalet/laravel-hashed-route)
[](https://github.styleci.io/repos/112489141)
[](https://packagist.org/packages/markwalet/laravel-hashed-route)A Laravel package that replaces the default route model binding for a safer version.
## Installation
You can install this package with composer:```shell
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:
```php
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:```php
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:
```shell
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.