mirror of
https://github.com/koel/koel
synced 2024-11-24 05:03:05 +00:00
20 lines
538 B
PHP
20 lines
538 B
PHP
<?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
|
|
{
|
|
return UserPreferences::fromArray(json_decode($value, true) ?: []);
|
|
}
|
|
|
|
/** @param UserPreferences|null $value */
|
|
public function set($model, string $key, $value, array $attributes): ?string
|
|
{
|
|
return json_encode($value ?: []);
|
|
}
|
|
}
|