Created
August 16, 2023 16:30
-
-
Save liamja/f0d0d7f402c9e4cbd8e8f0fbba5a484f to your computer and use it in GitHub Desktop.
UUID Livewire Synthesizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add to AppServiceProvider::boot() | |
Livewire::propertySynthesizer(\App\Livewire\Synths\UuidSynth::class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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