PHP code example of klongchu / laravel-uuid

1. Go to this page and download the library: Download klongchu/laravel-uuid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

klongchu / laravel-uuid example snippets


Uuid::generate()

(string) Uuid::generate()

Uuid::generate()->string

Uuid::generate(1,'00:11:22:33:44:55');

Uuid::generate(3,'test', Uuid::NS_DNS);

Uuid::generate(4);

Uuid::generate(5,'test', Uuid::NS_DNS);

$uuid = Uuid::import('d3d29d70-1d25-11e3-8591-034165a3a613');

$uuid = Uuid::generate(1);
dd($uuid->time);

$uuid = Uuid::generate(4);
dd($uuid->version);

/**
 *  Setup model event hooks
 */
public static function boot()
{
    parent::boot();
    self::creating(function ($model) {
        $model->uuid = (string) Uuid::generate(4);
    });
}

/**
 * Get the route key for the model.
 *
 * @return string
 */
public function getRouteKeyName()
{
    return 'uuid';
}

public function edit(Model $model)
{
   return view('someview.edit')->with([
        'model' => $model,
    ]);
}

$uuid = Uuid::generate();
$validator = Validator::make(['uuid' => $uuid], ['uuid' => 'uuid']);
dd($validator->passes());