samedi 26 septembre 2015

Laravel Request $request->file() is always blank

I have a form that has a field to upload multiple files. So far so good. So when I select a few files and hit the submit button, the $request->file() is always empty no matter what. The name of my field is images_json.

I suspected the route being PATCH or PUT could cause this (considering I'm uploading images on create and update), I made a separate POST route to handle the uploading with its own controller action and had a 3rd party jQuery plugin handle the upload (blueimp jQuery File Upload plugin), and guess... I'm receiving an empty response yet again!

And yes I have 'files' => true in my form tag and it spits the enctype="multipart/form-data" attribute very nicely.

This is what I have in my view currently (normal file upload that relies on the submit button of the form):

<div class="form-group form-md-line-input">
    {!! Form::label('images_json', 'Bilder hochladen', ['class' => 'col-md-2 control-label']) !!}
    <div class="col-md-10">
        <div class="fileinput fileinput-new" data-provides="fileinput">
            <span class="btn green-seagreen btn-file">
                <i class="glyphicon glyphicon-plus"></i>
                <span class="fileinput-new">Bilder auswählen...</span>
                <span class="fileinput-exists">Mehr auswählen</span>
                {!! Form::file('images_json[]', ['multiple']) !!}
            </span>
            <span class="fileinput-preview" style="max-height: 32px;"></span>
              <a href="javascript:;" class="close fileinput-exists" data-dismiss="fileinput"></a>
        </div>
    </div>
</div>

And this is the action:

public function update(CreateEntryRequest $request, $id)
{
    return $request->file('images_json');
}

And this would be a response:

[{},{},{}]

(Yes, I selected three pictures)

No matter what, it always comes back as blank. I have been stuck in this problem for a couple of days now, postponing it thinking it's a simple issue. But this is now something I am unable to figure out.

Help would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire