Laravel 11 Generate UUID Example
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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 11 Store JSON Format Data in Database Tutorial
- How to Integrate AdminLTE 3 in Laravel 11?
- Laravel 11 Event Broadcasting Tutorial
- Laravel 11 Confirm Box Before Delete Record from Database
- Laravel 11 Localization | Create Multi Language in Laravel 11
- Laravel 11 Client Side Form Validation using JQuery
- Laravel 11 Pagination Add Query String Example
- Laravel 11 Inertia Vue JS CRUD Example Tutorial
- How to Use Quill Rich Text Editor in Laravel 11?
- Laravel 11 Breeze Multi Auth Tutorial
- Laravel 11 Reverb Real-Time Notifications Example
- Laravel 11 Send Email with Attachment Example
- How to Generate Thumbnail Image in Laravel 11?