Download the PHP package matt-daneshvar/eloquent-hashids without Composer
On this page you can find all versions of the php package matt-daneshvar/eloquent-hashids. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
More information about matt-daneshvar/eloquent-hashids
Files in matt-daneshvar/eloquent-hashids
Short Description Automatically generate and persist Hashids for newly created Eloquent models.
Informations about the package eloquent-hashids
Eloquent Hashids for Laravel
Automatically persist Hashids on your newly created Eloquent models using Ivan Akimov's Hashids library.
This can be useful when you need to generate unique alphanumeric (or any other character) combinations to represent your models.
Require the package using composer.
Add a nullable
hashid column to your database table in your migrations.
Hashid trait to automatically generate and persist Hashids for your new models.
HashidRouting to set your model to use the
hashid column for
Laravel's Route Model Binding.
Customizing Hashid generation
While the package attempts to use sensible defaults to minimize configuration out of the box, you're free to adjust the Hashid generation behaviour using static properties on your model definition.
Changing the Hashid column
To customize the hashid column, set your own custom
$hashidColumn value on your model.
Changing the salt
Each model's table name is by default used as the salt for generating Hashids.
With that, models of separate classes that share the same IDs
Task model with ID of 1 and a
Receipt model also with ID of 1) would each have different Hashids.
You may change this behaviour and override the salt by specifying the
$hashidSlat on your model.
Creating your own Hashids instance
To fully customize the behaviour of the underlying Hashids library,
you may also define your own
Hashids instance in your model's boot method.
Note that your Hashids instance would take precedence over
all other customizations, and therefore all the rest of the static Hashid properties on your model
would be ignored once you specify your own
Using the HashidRouting trait
A common use case of Hashids with Eloquent models is to use short URLs using the generated Hashids as identifiers.
For example you may wish to represent your app's receipts using their Hashid values:
instead of their IDs:
For more convenience this package comes with a
HashidRouting trait out of the box; once added to your model,
this trait will change the model's route key name to its corresponding Hashid column,
which would allow you to take advantage of
Laravel's Route Model Binding
and use the Hashid URLs:
The MIT License (MIT). Please see License File for more information.