2021-06-04 16:19:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Casts;
|
|
|
|
|
|
|
|
use App\Values\UserPreferences;
|
|
|
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
|
|
|
|
|
|
class UserPreferencesCast implements CastsAttributes
|
|
|
|
{
|
|
|
|
public function get($model, string $key, $value, array $attributes): UserPreferences
|
|
|
|
{
|
2024-01-23 22:50:50 +00:00
|
|
|
return UserPreferences::fromArray(json_decode($value, true) ?: []);
|
2021-06-04 16:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @param UserPreferences|null $value */
|
|
|
|
public function set($model, string $key, $value, array $attributes): ?string
|
|
|
|
{
|
|
|
|
return json_encode($value ?: []);
|
|
|
|
}
|
|
|
|
}
|