2024-06-04 11:10:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Casts;
|
|
|
|
|
|
|
|
use App\Enums\SongStorageType;
|
|
|
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class SongStorageCast implements CastsAttributes
|
|
|
|
{
|
|
|
|
/** @param string|null $value */
|
|
|
|
public function get(Model $model, string $key, mixed $value, array $attributes): SongStorageType
|
|
|
|
{
|
|
|
|
return SongStorageType::tryFrom($value) ?? SongStorageType::LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @param SongStorageType|string|null $value */
|
2024-06-27 20:46:00 +00:00
|
|
|
public function set(Model $model, string $key, mixed $value, array $attributes): ?string
|
2024-06-04 11:10:44 +00:00
|
|
|
{
|
|
|
|
$type = $value instanceof SongStorageType ? $value : SongStorageType::tryFrom($value);
|
|
|
|
|
2024-06-27 20:46:00 +00:00
|
|
|
return $type?->value;
|
2024-06-04 11:10:44 +00:00
|
|
|
}
|
|
|
|
}
|