first of all i try to do the file uploading via ajax , when i try dd($request->all())in my controller , it give result empty array
public function uploadFile(Request $request){
dd($request->all());
}
My blade view with ajax
<label for="inputfile">
<a title="Click here to upload record "><i class="fa fa-upload"></i></a>
</label>
<input id="inputfile" name="inputfile" type="file" />
<script>
$('#inputfile').on('change',function(ev){
ev.preventDefault();
var postData=new FormData();
postData.append('file',this.files[0]);
$.ajax({
url:'{{url('reporting/uploadFile')}}',
headers:{'X-CSRF-Token':$('meta[name=csrf_token]').attr('content')},
type:"get",
contentType:false,
data:postData,
processData:false,
dataType:'json',
success: function( data ) {
console.log(data)
},
error: function() {
alert('error');
} }); });
</script>
My laravel version is 5.8 . The flow is when the user upload attachment, it will directly store to file storage without clicking button submit . But when i try to retrieve $request->all() its return empty array which is i can't continue further step. Sorry if my explaination not clear .
dd($request->file('file'))also empty? Sometimes it isn't included inall. Also check the console for any browser JS errorsgetfor form submission? You should usepostinstead, or in the case ofpatchyou need to append the formData_method: postfor getting files in laravel side'content-type' : 'multipart/form-data'