0

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.

1 Answer 1

2

you have to add name as projectGallery[]

 <input type="file" id="sectionGallery" name="projectGallery[]" multiple>

Also update validation

'projectGallery.*' => 'mimes:jpg,png,jpeg'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.