Download the PHP package mcris112/laravel-hashidable without Composer
On this page you can find all versions of the php package mcris112/laravel-hashidable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mcris112/laravel-hashidable
More information about mcris112/laravel-hashidable
Files in mcris112/laravel-hashidable
Package laravel-hashidable
Short Description LaravelHashidable - Hashids for Laravel Models and Routes
License MIT
Informations about the package laravel-hashidable
Laravel Hashidable
Laravel Hashidable uses Hashidable as main source
_I made this package because the main package from above never has been updated, that has a mistake in declaring types so when you want to use User::whereHashid()
Installation
Note: This package is built to work with Laravel versions greater than 7. It may work in older version, but this has not been tested.
Setup
Import the Hashidable
trait and add it to your model.
Usage
WhereHashid
This function needs two parameters.
$hashid needs to be a string and refers a plain hashed id text $columnId needs to be a string in case that your primary key It is different
Route Model Binding
Assuming we have a route resource defined as follows:
This package does not affect route model bindings, the only difference is, instead of placing the id in the generated route, it uses the hashid instead.
So, route('users.show', $user)
returns /users/3RwQaeoOR1E7qjYy
;
When you define your controller that auto-resolves a model in the parameters, it will work as always.
Configuring
First, publish the config file using:
The available configuration options are:
Per-Model Configuration
You can also extend the global configuration on a per-model basis. To do this, your model should implement the Mcris112\LaravelHashidable\HashidableConfigInterface
and define the hashidableConfig()
method on the model.
This method returns an array or subset of options similar to the global configuration.
FAQs
Where are the generated hashes stored?
Hashidable does not touch the database to store any sort of metadata. What it does instead is use an internal encoder/decoder to dynamically calculate the hashes.License
MIT