rollswan / uuid
Generates Universally Unique IDentifiers as primary key
Installs: 82
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/rollswan/uuid
This package is auto-updated.
Last update: 2025-10-05 02:42:01 UTC
README
A Laravel package to generate uuid as primary keys.
How to use?
- Install
composer require rollswan/uuid
- use
uuid()
in migration,
Example:
Schema::create('posts', function (Blueprint $table) {
$table->uuid(); // you can also custom your uuid `uuid('post_uuid')`
$table->string('title');
$table->string('body');
$table->timestamps();
});
- use
WithUuid
trait in your Model and declare the primary key
Example:
namespace App;
use Rollswan\Uuid\Traits\WithUuid;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use WithUuid;
protected $primaryKey = 'uuid';
}
Done! This will automatically generate unique UUID whenever you save a new record.