How to generate UUID in Laravel 5?

藏色散人
Release: 2023-04-05 14:34:02
Original
4904 people have browsed it

This article will introduce how to create a uuid in laravel 5. We will use the composer package to generate a unique uuid. UUID stands for Universally Unique Identifier, which is a 128-bit number used to identify information in a computer pc.

How to generate UUID in Laravel 5?

# Below we will use the webpatser/laravel-uuid composer package to generate uuid in laravel 5. We need to install the webpatser/laravel-uuid package into laravel first, and then generate uuid. Then to install the webpatser/laravel-uuid package, you only need to use the composer require command, as follows.

Install webpatser/laravel-uuid package:

composer require webpatser/laravel-uuid
Copy after login

Now, we are ready to use the "Uuid" facade, you can quickly get the Uuid from time, string, etc. Let us run the following route to generate the uuid.

Generate Uuid:

Route::get('uuid-gen', function () {
    dd(Uuid::generate()->string);
});
Copy after login

Uuid generate output:

480c7aa0-a40e-11e7-bb4c-4fc5af23e450
Copy after login

Related laravel video tutorial: "Latest laravel Mall practical video tutorial

As shown in the above example, it is very simple to generate uuid in laravel. I hope it will be helpful to friends in need!

The above is the detailed content of How to generate UUID in Laravel 5?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template