laragoon / uuid
Laragoon Uuid package
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
Installs: 118
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/laragoon/uuid
README
Uuid Trait for Laravel models
Installation
composer require laragoon/uuid
Uage
Add a uuid fields to the database table
$table->uuid('uuid')->unique()->index();
Then use the Laragoon\Uuid\Traits\HasUuid trait in the model
//app/Models/User.php namespace App\Models; use Laragoon\Uuid\Traits\HasUuid; class User extends Authenticatable { use HasUuid; }
It's all! Now when you create a record a Str::uuid() is generated and auto-fill the database field
User::create([ 'name' => 'John', 'email' => 'john@doe.com', 'password' => Hash::make('secret') ]);
You can now use the uuid field on your model instance
$user = User::where('name' => 'John')->get(); $user->uuid; // 4d2d3be9-194a-45ad-8157-7b5c01c35c39