Download the PHP package swiss-devjoy/laravel-easy-hashids without Composer
On this page you can find all versions of the php package swiss-devjoy/laravel-easy-hashids. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download swiss-devjoy/laravel-easy-hashids
More information about swiss-devjoy/laravel-easy-hashids
Files in swiss-devjoy/laravel-easy-hashids
Package laravel-easy-hashids
Short Description Easy HashIds for Laravel Eloquent models with Livewire Support
License MIT
Homepage https://github.com/swiss-devjoy/laravel-easy-hashids
Informations about the package laravel-easy-hashids
Easy HashIds for Laravel Eloquent Models with Livewire Support
A lightweight package that adds Hashid support to your Eloquent models. It automatically generates unique hashids for your models and includes Livewire support for only exposing the hashid as key to properly identify a public model.
Why Use HashIds?
- Security by Obscurity: Hide your sequential database IDs from users (although is not an encryption library)
- Predictability Prevention: Avoid exposing information about your data volume
- Performance: Invalid hashids don't lead to unnecessary database fetches (in most cases)
Features
- ✅ Easy integration with any Eloquent model
- ✅ Automatic hashid generation based on model IDs
- ✅ Livewire component support for passing models with hashids
- ✅ Route model binding support
- ✅ Auto generation of different hashids for different models, even if the ID is the same
- ✅ Configurable alphabet and minimum length globally and per model
- ✅ No database migrations needed - works with your existing models
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
-
Add the
HasHashid
andHashidRouting
traits to any Eloquent model: -
Access the hashid in your code:
- Use route model binding with hashids:
Configuration
The published config file contains these settings:
Working with Livewire
The package automatically handles Livewire integration. When passing models with the HasHashid
trait to Livewire components, their IDs will be converted to hashids:
The model will be automatically serialized with the hashid and reconstituted when needed.
Converting Between IDs and HashIds
You can manually convert between IDs and hashids:
Relationships
The package works seamlessly with Eloquent relationships:
Advanced Configuration
Model-Specific Settings
You can customize the alphabet and minimum hashid length for specific models in the config file:
Auto-Generated Alphabets
If no custom configuration is provided, the package will generate a unique alphabet for each model based on the class name. This ensures distinct hashids across different models even for identical database IDs.
For example, User::find(1)->hashid
will be different from Product::find(1)->hashid
.
Testing
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
- Dimitri König
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-easy-hashids with dependencies
illuminate/contracts Version ^10.0||^11.0||^12.0
spatie/laravel-package-tools Version ^1.16
sqids/sqids Version ^0.5.0