ItSolutionStuff.com

Laravel 11 Generate UUID Example

By Hardik Savani • September 30, 2024
Laravel

In this post, I will show you how to generate uuid in laravel 11 application. laravel provides string functions uuid() and orderedUuid() to generate uuid.

A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify something, like a record in a database. It's random and almost impossible to duplicate, ensuring each generated ID is unique, even across different systems.

So, let's see the following two ways to generate UUID:

Example 1:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Str;

class UserController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index(Request $request)
    {
        $uuid = Str::uuid()->toString();

        dd($uuid);
    }
}

You will receive output like this way:

f26f3923-a193-4013-a0b9-7ec827270ea9

Example 2:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Str;

class UserController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index(Request $request)
    {
        $uuid = Str::orderedUuid()->toString();

        dd($uuid);
    }
}

You will receive output like this way:

9d216595-3355-4f30-958f-1f7d8d4d66b0

I hope guys this will helps you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel 11 Store JSON Format Data in Database Tutorial

Read Now →

How to Integrate AdminLTE 3 in Laravel 11?

Read Now →

Laravel 11 Event Broadcasting Tutorial

Read Now →

Laravel 11 Confirm Box Before Delete Record from Database

Read Now →

Laravel 11 Localization | Create Multi Language in Laravel 11

Read Now →

Laravel 11 Client Side Form Validation using JQuery

Read Now →

Laravel 11 Pagination Add Query String Example

Read Now →

Laravel 11 Inertia Vue JS CRUD Example Tutorial

Read Now →

How to Use Quill Rich Text Editor in Laravel 11?

Read Now →

Laravel 11 Breeze Multi Auth Tutorial

Read Now →

Laravel 11 Reverb Real-Time Notifications Example

Read Now →

Laravel 11 Send Email with Attachment Example

Read Now →

How to Generate Thumbnail Image in Laravel 11?

Read Now →