Skip to content

Instantly share code, notes, and snippets.

@liamja
Created August 16, 2023 16:30
Show Gist options
  • Save liamja/f0d0d7f402c9e4cbd8e8f0fbba5a484f to your computer and use it in GitHub Desktop.
Save liamja/f0d0d7f402c9e4cbd8e8f0fbba5a484f to your computer and use it in GitHub Desktop.
UUID Livewire Synthesizer
// Add to AppServiceProvider::boot()
Livewire::propertySynthesizer(\App\Livewire\Synths\UuidSynth::class);
<?php
namespace App\Livewire\Synths;
use Livewire\Mechanisms\HandleComponents\ComponentContext;
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
class UuidSynth extends Synth
{
public function __construct(ComponentContext $context, $path)
{
parent::__construct($context, $path);
}
public static $key = 'uuid';
public static function match($target)
{
return $target instanceof UuidInterface;
}
public function dehydrate($target)
{
return [$target->toString(), []];
}
public function hydrate($value)
{
return Uuid::fromString($value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment