Category: Laravel, Laravel

One of the things I really love about Laravel is how easy it is to customize it to your own wishes. Recently I was working on a model that used a standard auto-incrementing integer as its primary key. My task was to convert this model to work with a https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random). It was actually quite simple, there are just a few protected attributes you have to change on the Eloquent model(s), as can be seen in this code sample: class Article extends Model { protected $primaryKey = 'uuid'; protected $keyType = 'string'; public $incrementing = false; }

This should not come as a surprise as authenticated uses the same Eloquent methods as we mentioned before.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners