koel/app/Rules/MediaPath.php

28 lines
720 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
2024-05-19 05:49:42 +00:00
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\File;
2024-05-19 05:49:42 +00:00
class MediaPath 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 = false;
if (config('koel.storage_driver') === 'local') {
2024-05-19 05:49:42 +00:00
$passes = $value && File::isDirectory($value) && File::isReadable($value);
}
2024-05-19 05:49:42 +00:00
if (!$passes) {
$fail(
config('koel.storage_driver') === 'local'
? 'Media path is required for local storage.'
: 'Media path is not required for non-local storage.'
);
}
}
}