Created
January 9, 2020 20:58
-
-
Save sebastiaanluca/d4b5d2b5611fe9320b7ffa525c5ea0fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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