fill id with uuid everywhere

This commit is contained in:
Daan Meijer 2026-06-23 17:17:47 +02:00
parent e7481eac95
commit ae925c7173
7 changed files with 36 additions and 8 deletions

View File

@ -0,0 +1,23 @@
<?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;
}
}

View File

@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Models\Chat; use App\Models\Chat;
use App\Concerns\SerializesIdToUuid;
class Dynamic extends Model class Dynamic extends Model
{ {
/** @use HasFactory<DynamicFactory> */ /** @use HasFactory<DynamicFactory> */
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'name', 'name',

View File

@ -9,11 +9,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class Ledger extends Model class Ledger extends Model
{ {
/** @use HasFactory<LedgerFactory> */ /** @use HasFactory<LedgerFactory> */
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'dynamic_id', 'dynamic_id',

View File

@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class Mutation extends Model class Mutation extends Model
{ {
/** @use HasFactory<MutationFactory> */ /** @use HasFactory<MutationFactory> */
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'ledger_id', 'ledger_id',

View File

@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class PredefinedMutation extends Model class PredefinedMutation extends Model
{ {
use HasFactory; use HasFactory, SerializesIdToUuid;
protected $fillable = [ protected $fillable = [
'ledger_id', 'ledger_id',

View File

@ -15,6 +15,7 @@ use Laravel\Fortify\Contracts\PasskeyUser;
use Laravel\Fortify\PasskeyAuthenticatable; use Laravel\Fortify\PasskeyAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Fortify\TwoFactorAuthenticatable;
use NotificationChannels\WebPush\HasPushSubscriptions; use NotificationChannels\WebPush\HasPushSubscriptions;
use App\Concerns\SerializesIdToUuid;
/** /**
* @property int $id * @property int $id
@ -34,7 +35,7 @@ use NotificationChannels\WebPush\HasPushSubscriptions;
class User extends Authenticatable implements PasskeyUser class User extends Authenticatable implements PasskeyUser
{ {
/** @use HasFactory<UserFactory> */ /** @use HasFactory<UserFactory> */
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable; use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable, SerializesIdToUuid;
public function dynamics() public function dynamics()
{ {

View File

@ -25,8 +25,8 @@ test('owner can view predefined mutations for ledger', function () {
$response->assertOk(); $response->assertOk();
$response->assertInertia(fn ($page) => $page $response->assertInertia(fn ($page) => $page
->component('Ledgers/PredefinedMutations/Index') ->component('Ledgers/PredefinedMutations/Index')
->where('dynamic.id', $dynamic->id) ->where('dynamic.id', $dynamic->uuid)
->where('ledger.id', $ledger->id) ->where('ledger.id', $ledger->uuid)
->has('predefined_mutations', 1) ->has('predefined_mutations', 1)
->where('predefined_mutations.0.name', 'Weekly Room Cleaning') ->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
); );
@ -112,7 +112,7 @@ test('owner can view edit form for predefined mutation', function () {
$response->assertOk(); $response->assertOk();
$response->assertInertia(fn ($page) => $page $response->assertInertia(fn ($page) => $page
->component('Ledgers/PredefinedMutations/Edit') ->component('Ledgers/PredefinedMutations/Edit')
->where('predefined_mutation.id', $predefined->id) ->where('predefined_mutation.id', $predefined->uuid)
); );
}); });