I have a form which sends the data to the controller through ajax
<script>
function save() {
$.ajax({
type: 'POST',
url: '{{url('/user/new')}}',
data: {
startDate: $('#startDate').val(),
nota: $('#nota').val(),
endDate: $('#endDate').val(),
file: $('#file').val()
}
,
success: function (data) {
// location.reload();
},
error: function (data) {
showAjaxErrors(data, 'error_msg');
markError(['startDate', 'endDate', 'nota']);
}
});
}
</script>
{{ Form::open(array('url' => '/save', 'files'=> 'true'), ['id' => 'absenceForm']) }}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="form-group">
{{ Form::text('startDate', null, ['class' => 'form-control date', 'placeholder' => 'Fecha Inicio', 'id' => 'startDate', 'title' => 'Fecha inicio']) }}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="form-group">
{{ Form::text('endDate', null, ['class' => 'form-control date', 'placeholder' => 'Fecha Fin', 'id' => 'endDate', 'title' => 'Fecha Fin']) }}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="form-group">
{{ Form::textarea('nota', null, ['class' => 'form-control', 'placeholder' => 'Nota', 'id' => 'note', 'rows' => '3', 'title' => 'Nota']) }}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-12">
<div class="form-group">
{{Form::file('file'),['id'=>'file']}}
</div>
</div>
</div>
<div class="modal-footer">
{{ Form::button('Guardar', ['class' => 'btn btn-primary', 'onClick' => 'save()']) }}
</div>
{{Form::close()}}
When doing dd($request->all());
just show me
array: 5 [ "startDate" = > "21-11-2018" "note" = > "Test note" "endDate" = > "21-11-2018" ]
But the value of the file field does not show it to me
And if I do dd($request->file('file'));
it shows me NULL
How do I get the value of the file to use in the controller?