Reputation: 172
I am trying to make an upload modal where the user can upload a project containing a Title, Cover image and gallery of images.
For that I thought about using the input element with the property 'multiple'.
<div class="addSection">
<form action="{{ route('architecture', ['locale' => app()->getLocale()] ) }}" method="POST" class="sectionUploader" enctype="multipart/form-data">
{{ csrf_field() }}
<label for="projectTitle">Project title: </label>
<input type="text" id="sectionTitle" name="projectTitle" placeholder=" (example: 1978-Reel-Boom)">
<label for="projectCover">Cover image: </label>
<input type="file" id="sectionCover" name="projectCover">
<br>
<label for="projectGallery">Gallery images: </label>
<input type="file" id="sectionGallery" name="projectGallery" multiple>
<button type="submit" id="uploadNewSection" name="uploadNewProject" value="Upload">Upload new project</button>
</form>
When doing a dd() on the projectGallery in my controller, I only recieve the latest selected image.
public function addProject(Request $request)
{
$request->validate([
'projectTitle' => 'required',
'projectCover' => 'image|mimes:jpg,png,jpeg|max:5048',
'projectGallery' => 'mimes:jpg,png,jpeg'
]);
dd($request->projectGallery);
}
Any Idea what I might be doing wrong? I just need an array of the selected images to upload the names into my DB table.
Upvotes: 0
Views: 98
Reputation: 15319
you have to add name as projectGallery[]
<input type="file" id="sectionGallery" name="projectGallery[]" multiple>
Also update validation
'projectGallery.*' => 'mimes:jpg,png,jpeg'
Upvotes: 2