© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo 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
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

File Upload Problem
FilamentFFilament / ❓┊help
3mo ago
Filament File Upload Custom Relationship
FilamentFFilament / ❓┊help
16mo ago
File upload with s3
FilamentFFilament / ❓┊help
3y ago
Custom validation message for File-upload
FilamentFFilament / ❓┊help
2y ago