Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

input type file not found the file but get null laravel

i have problem with my code. i make form to upload file to my database but my input type file get null object even if i have select image that i want

here my blade

<form action="/addcoaches" method="post">
            {{ csrf_field() }}
          <div class="input-field" style="margin-left:0;">
            <div class="form-group row">
                        <label for="name" class="col-md-4 col-form-label text-md-right">{{ __('File') }}</label>
                        <div class="col-md-6">
                            <input type="file" name="filename" required>
                        </div>
                    </div>
                    <div class="form-group row mb-0">
                        <div class="col-md-6 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Upload') }}
                            </button>
                        </div>
                    </div>
          </div>
</form>

here my controller

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public function saveCoach(Request $request)
    {
        $request->validate([
            'filename' => 'required',
            'filename.*' => 'mimes:doc,docx,PDF,pdf,jpg,jpeg,png|max:2000'
        ]);

        dd($request->file('filename'));
     }

here what my dd after i click upload button
enter image description here

how to get the file from selected file. Thank you

>Solution :

Your encoding is wrong.
When you make a POST request, you have to encode the data the right way. (link)

In your case you want to encode your form with multipart/form-data

<form enctype='multipart/form-data' action="/addcoaches" method="post">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading