Category: Laravel, PHP, api

UUIDs (Universally Unique Identifier) are 128 bits values, used to uniquely identify the table records. A typical example looks like: The point of this article is not to address the advantages or disadvantages of using UUIDs, but to see how to implement them in a Laravel app and update any foreign key based on a UUID column. For the purpose of this article, we are going to be using Laravel 7.x, but this can work on any other version of Laravel (Tested on 5.8 and 6.x).

Your imports and Use statements should look like: Next let’s transform our users migration to use UUID instead of auto-increments.

If you are using a UUID primary key as a foreign key in another table, you need to change the column type to uuid, where the foreign key is defined.
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