~/docs
Resonate
Resonate
9.x 9.0.0, current 8.x 8.0.0 7.x 7.0.1 6.x 6.2.1 5.x 5.1.2 4.x 4.0.2
Laravel UUID
Toggle sidebar
Laravel UUID
webpatser/laravel-uuid 9.0.0

Laravel UUID 9.x

Installation

Install Laravel UUID 9.x, the Laravel integration for webpatser/uuid with Str macros, Eloquent traits and casts.

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