mirror of
https://github.com/koel/koel
synced 2024-12-18 16:44:03 +00:00
24 lines
706 B
PHP
24 lines
706 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Casts;
|
||
|
|
||
|
use App\Values\SmartPlaylistRuleGroup;
|
||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||
|
use Illuminate\Support\Collection;
|
||
|
|
||
|
class SmartPlaylistRulesCast implements CastsAttributes
|
||
|
{
|
||
|
/** @return Collection|array<SmartPlaylistRuleGroup> */
|
||
|
public function get($model, string $key, $value, array $attributes): Collection
|
||
|
{
|
||
|
return collect(json_decode($value, true) ?: [])->map(static function (array $group): ?SmartPlaylistRuleGroup {
|
||
|
return SmartPlaylistRuleGroup::create($group);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public function set($model, string $key, $value, array $attributes): ?string
|
||
|
{
|
||
|
return json_encode($value ?: []);
|
||
|
}
|
||
|
}
|