Download the PHP package io238/eloquent-encoded-ids without Composer
On this page you can find all versions of the php package io238/eloquent-encoded-ids. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download io238/eloquent-encoded-ids
More information about io238/eloquent-encoded-ids
Files in io238/eloquent-encoded-ids
Package eloquent-encoded-ids
Short Description Automatic route key encryption for Laravel Eloquent using Hashids (short, unique, non-sequential ids) with prefix support
License MIT
Homepage https://github.com/io238/eloquent-encoded-ids
Informations about the package eloquent-encoded-ids
Eloquent Encoded IDs
Automatic route key encryption for Laravel Eloquent using Hashids (short, unique, non-sequential IDs) with prefix support.
Background
By default Laravel uses numeric, sequential IDs for models. These numeric IDs are then also used as route keys:
This package automatically encodes the model ID, so that sequence is not externally exposed:
This is useful to hide sensitive app information (e.g. total number of users, invoices, etc).
Installation
You can install the package via composer:
Usage
In order to encode the ID of a Laravel model, simply add the HasEncodedIds
trait to the model:
Internally, Laravel will still use the numeric ID within controllers and also stores them as numeric IDs in the database:
Prefixes
By default this package adds a prefix to the encoded ID, which helps to identify what type of ID has been encoded.
Example: The User
model has encoded IDs starting with u_
, such as u_m8y78
.
It uses the model name's first letter, or you can explicitly provide a prefix as a protected property of the model:
Config
This package works out-of-the-box. Nevertheless, you can publish and customize the config file with:
This is the contents of the default config file:
Testing
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review the security policy on how to report security vulnerabilities.
Credits
- Martin Migge
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of eloquent-encoded-ids with dependencies
hashids/hashids Version ^4.1
illuminate/database Version ^8.0|^9.0
illuminate/support Version ^8.0|^9.0