Last active
February 19, 2025 20:27
-
-
Save atomjoy/9bd19af1f78e6d55289087858b551125 to your computer and use it in GitHub Desktop.
Laravel Uuid model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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