Laravel UUID connects the webpatser/uuid library to Laravel: Str macros, Eloquent traits and casts, binary UUID migration helpers and SQL Server GUID conversion.
Requirements
- PHP 8.6 or higher
- Laravel 13.x
webpatser/uuid^4.0 (installed as a dependency)
Note: The package supports only the latest stable PHP release. When a new PHP version is released, the next release of this package requires it and support for the previous PHP version ends.
Install
composer require webpatser/laravel-uuid
The service provider (Webpatser\LaravelUuid\UuidServiceProvider) and the Uuid facade alias (Webpatser\LaravelUuid\UuidFacade) are auto-discovered. The provider registers the Str macros on boot. There is no config file to publish.
Not using Laravel?
If you do not need the Eloquent traits, Str macros or casts, use the core library directly: webpatser/uuid.
What is included
| Class | Purpose |
|---|---|
Webpatser\LaravelUuid\UuidMacros |
Str macros for generation, validation, binary and SQL Server conversion |
Webpatser\LaravelUuid\UuidFacade |
Facade class for Webpatser\Uuid\Uuid; the alias is registered but does not resolve in 8.0.0 and 9.0.0, so use Webpatser\Uuid\Uuid directly |
Webpatser\LaravelUuid\HasUuids |
Eloquent trait, generates UUID v7 keys by default |
Webpatser\LaravelUuid\HasBinaryUuids |
Eloquent trait for 16-byte binary keys |
Webpatser\LaravelUuid\UuidCast |
Cast a string column to a Uuid object |
Webpatser\LaravelUuid\BinaryUuidCast |
Cast a binary column to a Uuid object |
Webpatser\LaravelUuid\BinaryUuidMigrations |
Migration helpers for binary UUID columns |
Verify the installation
php artisan tinker
use Illuminate\Support\Str;use Webpatser\Uuid\Uuid; echo Str::fastUuid(); // random UUID (v4)echo Str::fastOrderedUuid(); // time-ordered UUID (v7)echo Uuid::v7();
Next steps
- Quick Start: the
Strmacros and the coreUuidclass. - Eloquent Models: UUID primary keys and casts.
- Upgrade: moving from 8.x to 9.x.