loading...

Laravel Eloquent Model UUID Route Keys

ryancco profile image Ryan ・1 min read

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.

Posted on by:

ryancco profile

Ryan

@ryancco

I am a web developer interested in TDD, mentoring/giving back where possible, developer-first-DevOps, and Laravel.

Discussion

pic
Editor guide