PHP code example of juniorb2ss / eloquent-uuid

1. Go to this page and download the library: Download juniorb2ss/eloquent-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/ */

    

juniorb2ss / eloquent-uuid example snippets


use juniorb2ss\EloquentUuid\EloquentUuidTrait;

class User extends Authenticatable
{
    use Notifiable, EloquentUuidTrait;
    
    /**
    * UUID Column name used
    * 
    * @var string
    * @optional 
    */
    protected $uuidKey = 'uuid';
}

$fields = $request->only(['email', 'name', 'password']);
$user = User::create($fields); // Creating user with auto-inject uuid field

dump($user->toArray());

/*[
    "id" => "1"
    "uuid" => "723e4628-7c35-11e7-89b1-0242bfc0df57",
    "name" => "Magdalena Zboncak"
    "email" => "[email protected]"  
  ]*/


use App\User;

$user = (new User)->onUuid('aae5f3f1-0f22-4a8b-9291-d2a9649d1490')
                  ->firstOrFail();