Skip to content

Instantly share code, notes, and snippets.

@sebastiaanluca
Created January 9, 2020 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastiaanluca/d4b5d2b5611fe9320b7ffa525c5ea0fa to your computer and use it in GitHub Desktop.
Save sebastiaanluca/d4b5d2b5611fe9320b7ffa525c5ea0fa to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Passport\Models;
use Closure;
use Laravel\Passport\Client as PassportClient;
use Ramsey\Uuid\Uuid;
class Client extends PassportClient
{
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'string';
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot() : void
{
parent::boot();
static::creating(Closure::fromCallable([static::class, 'generateAndAssignId']));
}
/**
* @param \Passport\Models\Client $client
*/
private static function generateAndAssignId(Client $client) : void
{
if ($client->id !== null) {
return;
}
$client->id = Uuid::uuid4()->toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment