Home  >  Article  >  Backend Development  >  How to generate UUID in Laravel 5?

How to generate UUID in Laravel 5?

藏色散人
藏色散人Original
2019-03-08 14:43:204896browse

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

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);
});

Uuid generate output:

480c7aa0-a40e-11e7-bb4c-4fc5af23e450

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!

Statement:
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