fill id with uuid everywhere
This commit is contained in:
parent
e7481eac95
commit
ae925c7173
23
app/Concerns/SerializesIdToUuid.php
Normal file
23
app/Concerns/SerializesIdToUuid.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Chat;
|
||||
use App\Concerns\SerializesIdToUuid;
|
||||
|
||||
class Dynamic extends Model
|
||||
{
|
||||
/** @use HasFactory<DynamicFactory> */
|
||||
use HasFactory;
|
||||
use HasFactory, SerializesIdToUuid;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
||||
@ -9,11 +9,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Concerns\SerializesIdToUuid;
|
||||
|
||||
class Ledger extends Model
|
||||
{
|
||||
/** @use HasFactory<LedgerFactory> */
|
||||
use HasFactory;
|
||||
use HasFactory, SerializesIdToUuid;
|
||||
|
||||
protected $fillable = [
|
||||
'dynamic_id',
|
||||
|
||||
@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Concerns\SerializesIdToUuid;
|
||||
|
||||
class Mutation extends Model
|
||||
{
|
||||
/** @use HasFactory<MutationFactory> */
|
||||
use HasFactory;
|
||||
use HasFactory, SerializesIdToUuid;
|
||||
|
||||
protected $fillable = [
|
||||
'ledger_id',
|
||||
|
||||
@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Concerns\SerializesIdToUuid;
|
||||
|
||||
class PredefinedMutation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, SerializesIdToUuid;
|
||||
|
||||
protected $fillable = [
|
||||
'ledger_id',
|
||||
|
||||
@ -15,6 +15,7 @@ use Laravel\Fortify\Contracts\PasskeyUser;
|
||||
use Laravel\Fortify\PasskeyAuthenticatable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||
use App\Concerns\SerializesIdToUuid;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -34,7 +35,7 @@ use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||
class User extends Authenticatable implements PasskeyUser
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
||||
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable, SerializesIdToUuid;
|
||||
|
||||
public function dynamics()
|
||||
{
|
||||
|
||||
@ -25,8 +25,8 @@ test('owner can view predefined mutations for ledger', function () {
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn ($page) => $page
|
||||
->component('Ledgers/PredefinedMutations/Index')
|
||||
->where('dynamic.id', $dynamic->id)
|
||||
->where('ledger.id', $ledger->id)
|
||||
->where('dynamic.id', $dynamic->uuid)
|
||||
->where('ledger.id', $ledger->uuid)
|
||||
->has('predefined_mutations', 1)
|
||||
->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->assertInertia(fn ($page) => $page
|
||||
->component('Ledgers/PredefinedMutations/Edit')
|
||||
->where('predefined_mutation.id', $predefined->id)
|
||||
->where('predefined_mutation.id', $predefined->uuid)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user