DEV Community

Ryan
Ryan

Posted on

Laravel Eloquent Model UUID Route Keys

Without arguing the reason for the packages conception, auto-incrementing keys in URLs are often discussed as an anti-pattern, security flaw, and generally ugly (see here, here, here for a few).

Laravel UUID Models provides a trait that, when applied to a Laravel Eloquent Model, seamlessly handles allowing it to be routed using UUID's (rather than auto-incrementing ID's).

Additionally, there are no further code changes required for generating the time ordered UUID, validation, type-casting, or editing any existing routes or links*. It's as simple as installing the package, placing the trait on the eloquent models you would like to use UUID route keys, and adding a migration to store the UUID field.

Any suggestions or changes are always encouraged and welcomed on the repository.

* All routes will work assuming they're generated with the route() helper.

Top comments (0)