Implement UUID on Authentication Built-in Laravel 5.7

Image for post
Image for post
Implement UUID on Laravel 5.7

Hi guys,

I want to implement UUID on my Laravel 5.7 project. By default Laravel has provided great features in it, we can have authentication by just running simple command php artisan make:auth, then Laravel will provide these all for us. We can have a login’s page, a register’s page and a forgot password’s page just in second.

But I’m not trying to explain this now, and I supposed you have already know this or you can check this out here .

Now when you have Laravel’s built-in authentication feature that by default it was implemented auto-increment’s integer on its user ID.

So how if we want to change it to UUID based? Here it is I’m going to share with you all about this.

Create migration to change `id` column to accept UUID

Run this command:

php artisan make:migration change_user_id_to_uuid —table=users

This command above will generate migration file like this:


Then open up migration file that just created, you may see different file name because migration will create based on timestamp you run at.
And make sure you modify that migration’s file like just code below.


Then run migrate to start changing your database: php artisan:migrate . If you found some problems regarding migration, try to truncate your users’s table first, and make sure users’s table empty before running migration again.

Modify User’s Eloquent Model

After you run migration and succeeded, then you can modify User’s model, open up app\User.php

I’m using UUID Generator library from webpaster, so if you want to follow me, you should add

composer require “webpatser/laravel-uuid”: “3.0”

then run command composer update then do the following changes like code below:


I also made some UUID Wrapper for Laravel to generate UUID, you can use it too if you want and here it is

Anyway, hope this help and see you later …

Written by

10 years experience in Web development …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store