koel/app/Rules/ValidSmartPlaylistRulePayload.php

21 lines
530 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
use App\Values\SmartPlaylistRuleGroupCollection;
2024-05-19 05:49:42 +00:00
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Arr;
2024-05-19 05:49:42 +00:00
class ValidSmartPlaylistRulePayload implements ValidationRule
{
2024-05-19 05:49:42 +00:00
public function validate(string $attribute, mixed $value, Closure $fail): void
{
2024-05-19 05:49:42 +00:00
$passes = (bool) attempt(static fn () => SmartPlaylistRuleGroupCollection::create(Arr::wrap($value)));
2024-05-19 05:49:42 +00:00
if (!$passes) {
$fail('Invalid smart playlist rules');
}
}
}