maarheeze / uuid-livewire
livewire integration for a simple uuid value object
Requires
- php: ^8.4
- livewire/livewire: ^4.2
- maarheeze/uuid: ^3.0
Requires (Dev)
- maarheeze/phpcs: ^3.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13
Suggests
- maarheeze/uuid-laravel: Eloquent cast and primary key support for Laravel models
Provides
None
Conflicts
None
Replaces
None
README
Livewire integration for maarheeze/uuid.
Livewire serializes component properties between requests. Without this package, it does not know how to handle Uuid value objects and will fail when one is used as a property. This package registers a property synthesizer that teaches Livewire how to serialize and deserialize Uuid instances automatically.
Installation
composer require maarheeze/uuid-livewire
Usage
Custom Livewire components
Declare a Uuid property directly — no manual conversion needed.
use Livewire\Component; use Maarheeze\Uuid\Uuid; class ShowArticle extends Component { public Uuid $articleId; }
Typed identifiers
Typed identifiers — your own classes using the IsUuid trait — are supported the same way, and keep their own type across requests. A PlayerId property hydrates back as a PlayerId, never as a plain Uuid.
use Livewire\Component; use App\Player\PlayerId; class ShowPlayer extends Component { public PlayerId $playerId; }
This also covers properties updated from the browser, such as wire:model bindings and url parameters.
Filament
Filament pages are Livewire components. When a Filament resource uses a Uuid as its primary key, Livewire needs to serialize it between requests — for example, when loading an edit page. Without this package, Filament will fail to keep track of the record.
use Filament\Resources\Resource; use App\Models\Article; // model with a Uuid primary key class ArticleResource extends Resource { protected static string $model = Article::class; }
No additional configuration is required in either case — installing this package is enough.
License
MIT