mirror of
https://github.com/koel/koel
synced 2024-12-23 19:13:06 +00:00
23 lines
709 B
PHP
23 lines
709 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::tryCreate($group);
|
|
});
|
|
}
|
|
|
|
public function set($model, string $key, $value, array $attributes): ?string
|
|
{
|
|
return json_encode($value ?: []);
|
|
}
|
|
}
|