Files
RomhackPlaza/app/Rules/PublicFileExists.php

24 lines
593 B
PHP
Raw Normal View History

2026-05-20 18:25:15 +02:00
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Storage;
use Illuminate\Translation\PotentiallyTranslatedString;
class PublicFileExists implements ValidationRule
{
/**
* Run the validation rule.
*
* @param Closure(string, ?string=): PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if(!Storage::disk('public')->exists($value) ) {
$fail("The file {$value} does not exist.");
}
}
}