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'),
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?