Fileupload null
Hey,
When I try to upload a file like this:
<div class="form-group">
<label for="File upload" class="col-lg-2 control-label" >File upload</label>
<div class="col-lg-10">
<input action="" type="file" id="fileinput" enctype="multipart/form data"/>
</div>
</div>
When I this in my controller:
public function storeTicket(makeTicketRequest $request)
{
dd($request->get("file"));
}
It's telling me null. In Jeffreys video he's telling me to add:
enctype="multipart/form data"
But that's not working?
- Your code lacks a form.
- It's
enctype="multipart/form-data" (notice the hyphen)
- Your input has no name attribute.
- I don't think ID attributes can have spaces.
- By default laravel uses CSRF validation (so you need a
_token field)
Try this:
<form action="… action here …" enctype="multipart/form-data" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="File upload" class="col-lg-2 control-label" >File upload</label>
<div class="col-lg-10">
<input type="file" id="fileInput" name="file" />
</div>
</div>
</form>
The enctype="multipart/form-data" attribute should be added to your <form> element. You are also missing a name attribute for your file input.
<form action="/path/to/upload/route" method="POST" enctype="multipart/form-data">
<input id="file" name="file" type="file">
</form>
I think you should be using $request->file('file') to get the file too.
^ This too. Missed the usage of ->get(). Good catch.
Please or to participate in this conversation.