ledgerrz/app/Concerns/SerializesIdToUuid.php
2026-06-23 17:17:47 +02:00

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;
}
}