Skip to content

Commit

Permalink
strip uuid dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
crysg committed Jan 7, 2025
1 parent ffcff8c commit 66292d8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
7 changes: 3 additions & 4 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Laravel\Jetstream\Events\TeamCreated;
use Laravel\Jetstream\Events\TeamDeleted;
use Laravel\Jetstream\Events\TeamUpdated;
use App\Traits\Uuid;
use Laravel\Jetstream\Team as JetstreamTeam;
#use App\Traits\Uuid;
use Illuminate\Database\Eloquent\Concerns\HasUuids; # uuids contain dashes

class Team extends JetstreamTeam
{
use HasFactory;
#use Uuid;
use HasUuids;
use Uuid;

/**
* The attributes that should be cast.
Expand Down
13 changes: 6 additions & 7 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use App\Traits\Uuid;
use Laravel\Sanctum\HasApiTokens;
#use App\Traits\Uuid;
use Illuminate\Database\Eloquent\Concerns\HasUuids; # uuids contain dashes

class User extends Authenticatable
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use HasTeams;
use Uuid;
use Notifiable;

use TwoFactorAuthenticatable;
#use Uuid;
use HasUuids;


/**
* The attributes that are mass assignable.
*
Expand All @@ -36,7 +35,7 @@ class User extends Authenticatable
'google_id',
'google_token',
'google_refresh_token',
];
];

/**
* The attributes that should be hidden for serialization.
Expand Down
26 changes: 26 additions & 0 deletions app/Traits/Uuid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Traits;

use Illuminate\Support\Str;

trait Uuid
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->id = str_replace('-', '', (string) Str::uuid());
});
}

public function getIncrementing(): bool
{
return false;
}

public function getKeyType(): string
{
return 'string';
}
}

0 comments on commit 66292d8

Please sign in to comment.