Hm.... $request->image is just a string containing the filename... But how can I achieve this to actually be the file uploaded? On the website I have:
<input type="file" class="form-control" accept=".png" name="image" id="image">
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello there! I am currently trying to make a form that lets users create posts and optionally also add images to them. For Validation, I did the following:
$request->validate([
'content' => 'required|max:3000',
'image' => 'nullable|image|mimes:png|max:2048',
'title' => 'required|max:500',
'topic' => [
'required',
Rule::in(["topic1", "topic2",])
]
]);
When I try to submit the form (which does a POST to the Endpoint where the Validation is) it works as long as I don't put an image. But if I put an image, I get an error saying "The image must be an image." Does anyone know what causes this and how I could fix this? I already tried searching for people having similar problems on the Internet but wasn't able to find anything.
does your form include enctype="multipart/form-data"?
<form method="POST" enctype="multipart/form-data">
Please or to participate in this conversation.