Skip to content

Instantly share code, notes, and snippets.

@atomjoy
Last active February 19, 2025 20:27
Show Gist options
  • Save atomjoy/9bd19af1f78e6d55289087858b551125 to your computer and use it in GitHub Desktop.
Save atomjoy/9bd19af1f78e6d55289087858b551125 to your computer and use it in GitHub Desktop.
Laravel Uuid model.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Support\Str;
/**
* Uuid class
*
* // Table key
* $table->uuid('id')->primary();
*
* // Column
* $table->uuid('user_id');
*
* // Relation with column
* $table->foreignUuid('user_id')->constrained();
* $table->uuidMorphs('tokenable');
*/
class Uuid extends Model
{
use HasUuids;
// protected $incrementing = false;
// protected $keyType = 'string';
// protected $primaryKey = 'id';
public static function generateUuid(): string
{
return (string) Str::uuid();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment