Download the PHP package deligoez/laravel-model-hashid without Composer
On this page you can find all versions of the php package deligoez/laravel-model-hashid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download deligoez/laravel-model-hashid
More information about deligoez/laravel-model-hashid
Files in deligoez/laravel-model-hashid
Package laravel-model-hashid
Short Description Generate, Save, and Route Stripe/Youtube-like Hash IDs for Laravel Eloquent Models
License MIT
Homepage https://github.com/deligoez/laravel-model-hashid
Informations about the package laravel-model-hashid
Using this package you can generate, save and, route Stripe-like Hash Ids for your Eloquent Models.
Hash Ids are short, unique, and non-sequential, and can generate unique Ids for URLs and hide database row numbers from the user. For more information about Hash Ids please visit hashids.org.
With this package, you can customize Hash Id generation and add a model prefix and also separator.
For a User
model with an id of 1234
, you can generate Hash Ids like user_kqYZeLgo
.
So instead of;
https://your-endpoint.com/user/1234
You can have endpoints like;
https://your-endpoint.com/user/user_kqYZeLgo
You have complete control over your Hash Id length and style. Check out the configuration file for more options.
Table of contents
- Features
- Compatibility Table
- Installation
- Usage
- Model Hash Id Generation
- Routing and Route Model Binding (Optional)
- Saving Hash Ids to the Database (Optional)
- Hash Id Terminology
- Configuration
- Roadmap
- Testing
- Used By
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Features
- Customizable Hash Id Generation
- Hash Id Salt
- Length
- HashID Alphabet
- Model Prefix Length and Case
- Separator
- Model Specific Hash Id Generation
- User-defined prefix per Model (optional)
- Define separate configurations per Model
- Route (Model) Binding using Hash Ids (optional)
- Automatically save Hash Ids to the database (optional)
Compatibility Table
The table below shows the compatibility across Laravel, PHP, and this package's current version.
Package Version | Laravel version | PHP version | Compatible |
---|---|---|---|
^2.0 | 9. , 10. | 8.1.* | ✅ |
^1.0 | 8.* | 8.0.* | ✅ |
8.* | 7.4.* | ❌ | |
8.* | 7.3.* | ❌ | |
7.x | * | ❌ |
Installation
-
Install via Composer:
- Publish the config file:
Usage
Model Hash Id Generation
Add the HasHashId
trait to any Laravel Model that should use Hash Ids.
Model Attributes and Static Model Functions
You will be able to use hashId
and hashIdRaw
attributes and keyFromHashId()
static model function.
Query Builder Functions
You can use all finding related Laravel query builder functions with Hash Ids.
Routing and Route Model Binding (Optional)
Simply add the HasHashIdRouting
trait to your model that you want to route using Hash Ids.
Route Model Binding (Implicit)
You can define a route and/or controller method like this by Laravel conventions.
Route Model Binding (Explicit)
You can also define a custom model key on your RouteServiceProvider
.
Saving Hash Ids to the Database (Optional)
You can add the SavesHashId
Trait to any of your Laravel Model that should save the generated Hash Ids.
After that, you should set database_column
setting in the configuration file. You can define database_column
setting
per model separately or for all of your models.
All Hash Id generation or decoding methods work ON-THE-FLY. So you DO NOT need to save Hash Ids to the database for that reason.
Since generating a Hash Id requires an integer model id/key, remember that storing the Hash Ids to a database will result in an additional database query.
Hash Id Terminology
A typical Hash Id consist of 3 parts.
- Model Prefix (
model_a
) - Separator (
_
) - Raw Hash Id (
kqYZeLgo
)
Model Prefix and Separator are OPTIONAL. You can generate Hash Ids that only contains Raw Hash Ids.
Configuration
This is the contents of the published config file:
Roadmap
- [x] Custom Model Prefixes (Not generated from a Model name) (Thanks to @plunkettscott)
- [ ] Hash Id Validation Rules
- [ ] Generic Generators (Not bound to a Laravel Model)
Testing
Used By
This project is used by the following companies/products, you can add yours too:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Yunus Emre Deligöz
- Scott Plunkett
- Wade
- Laravel Shift
- Faruk
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-model-hashid with dependencies
ext-mbstring Version *
hashids/hashids Version ^4.1|^5.0
illuminate/contracts Version ^9.0|^10.0|^11.0