Download the PHP package jdavidbakr/ulidmodelroutes without Composer
On this page you can find all versions of the php package jdavidbakr/ulidmodelroutes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jdavidbakr/ulidmodelroutes
More information about jdavidbakr/ulidmodelroutes
Files in jdavidbakr/ulidmodelroutes
Package ulidmodelroutes
Short Description Configures models to have ULID route keys while still having integer primary keys
License MIT
Homepage https://github.com/jdavidbakr/ulidmodelroutes
Informations about the package ulidmodelroutes
Ulidmodelroutes
Configures models to have ULID or UUID route keys while still having integer primary keys
Installation
You can install the package via Composer:
If you want to change the default ULID column name, publish the config file:
Usage
Add an identifier column to each model table that should be used for route model binding. Keep it indexed and unique.
For ULIDs:
For UUIDs:
Apply the trait to the model.
Once the trait is applied:
- new models receive a route identifier automatically when they are created
- URL generation uses the configured route identifier instead of the integer primary key
- implicit route model binding resolves records by the configured route key column
Example route:
Example URL generation:
Customizing the column name per model
If a model should use a different route key column, define ulidRouteKeyColumnName on that model.
Setting a package-wide default column
After publishing the config file, change the default column name:
Switching between ULID and UUID
By default, the package generates ULIDs.
You can switch to UUID generation in the config file:
Notes:
ulidkeeps lexicographic ordering and supportscreated_at-based backfill timestamps.uuid7is time-ordered and also supportscreated_at-based backfill timestamps.uuid4is random and does not preserve chronological sort order.
Existing data
This package does not create database columns for you. If you are adding route identifiers to an existing table, add the column in a migration and then backfill missing values before making the column unique.
You can backfill an existing model with the included Artisan command:
The command only fills missing route key values. When a row has a created_at value, the generated ULID or UUIDv7 uses that timestamp so the resulting identifiers stay as close as possible to the model's original creation order.
Recommended rollout for existing tables:
- Add the nullable ULID column.
- Run the backfill command for the model.
- Verify all rows have values.
- Add the unique index and, if desired, make the column non-nullable.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Thank you for considering contributing to UlidModelRoutes.
Security Vulnerabilities
Please open a private security advisory or contact the maintainer directly if you discover a vulnerability.
Credits
License
Ulidmodelroutes is open-sourced software licensed under the MIT license.
All versions of ulidmodelroutes with dependencies
illuminate/database Version ^12.0||^13.0
illuminate/support Version ^12.0||^13.0