24 lines
444 B
PHP
24 lines
444 B
PHP
<?php
|
|
|
|
namespace App\Concerns;
|
|
|
|
trait SerializesIdToUuid
|
|
{
|
|
/**
|
|
* Convert the model's attributes to an array.
|
|
* Overrides the default model toArray method to replace 'id' with 'uuid'.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
$array = parent::toArray();
|
|
|
|
if (isset($this->uuid)) {
|
|
$array['id'] = $this->uuid;
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
}
|