FilamentF
Filament10mo ago
ashfall

Problem with Custom rules - upload file

If I add required outside, it automatically reports an error that no file is loaded even though I have loaded it. If I put it in fn, it will skip the fn without loading the file. So where is the problem I have?

FileUpload::make('cover_image')
->placeholder('は JPEG ')
->disk('public')
->rules([
fn(): Closure => function (string $attribute, $value, Closure $fail) {

if (!$value) {
$fail('');
return;
}
// Kiểm tra mime type
$mime = $value->getMimeType();
if (!in_array($mime, ['image/jpeg'])) {
$fail('がJPEG/JPG');
return;
}

$tmpPath = $value->getRealPath();
$imageInfo = getimagesize($tmpPath);
if (!$imageInfo) {
$fail('');
return;
}

$width = $imageInfo[0];
$height = $imageInfo[1];

if ($width < 3000 || $height < 3000) {
$fail('は3000px×3000px');
}
return;
},
])
->directory('cover_image'),
image.png
Was this page helpful?