adrema/app/Setting/Data/SettingSynthesizer.php

37 lines
743 B
PHP
Raw Normal View History

2024-10-14 21:21:19 +02:00
<?php
namespace App\Setting\Data;
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
use Spatie\LaravelSettings\Settings;
class SettingSynthesizer extends Synth
{
public static $key = 'setting-class';
public static function match($target)
{
return $target instanceof Settings;
}
public function dehydrate($target)
{
return [$target->toArray(), ['setting_class' => get_class($target)]];
}
public function hydrate($value, $meta)
{
return app($meta['setting_class'])->fill($value);
}
public function get(&$target, $key)
{
return $target->{$key};
}
public function set(&$target, $key, $value)
{
$target->{$key} = $value;
}
}