Laravel Story: Replace Auto Increment ID with UUID
Here is the simple steps that you need to do to replace Auto Increment ID that generated from Laravel Authentication Quickstart.
First, install Ramsey UUID with this following commands.
composer require ramsey/uuid
Seconds, replace increment to uuid on users database migration.
Third, add UUID on register user process. Open the RegisterController.php file. Then use Ramsey UUID
After that, add this line on create function
'id' => Uuid::uuid4(),
Last steps is modifying the user model. So open the User.php file and ID to the fillable array
* The attributes that are mass assignable.
* @var array
protected $fillable = [
'id', 'name', 'email', 'password',
Add this code to disable the auto increments process.
* Indicates if the IDs are auto-incrementing.
* @var bool
public $incrementing = false;
After all those steps, every time new users registered it will automatically generate the UUID as their ID.
With auto increments, the user ID will be shown like this:
With UUID, the user ID will became like this:
Laravel Story is a series of articles about Learning Laravel. You can fork the sources code from here: