i need to upload excel file and create datatable from array. How to do that? I have problem with making postExcel return.
im using http://www.maatwebsite.nl/laravel-excel/docs and http://datatables.net/
Here is my code:
public function postExcel(Request $request)
{
if($request->ajax()) {
if ($request->hasFile('file'))
{
$file = $request->file('file');
$filename = $file->getClientOriginalName();
//$file->getRealPath();
$path = $file->move(public_path(), $filename);
\Excel::load($path, function($reader){
$results = $reader->toArray();
});
print_r($results);die();
$json = array(
'status' => 'ok',
'array' => $results
);
}
return Response::json($json);
}
}
and this is views js there i need generate table:
$(document).on("change", "#file-input", function() {
var formData = new FormData($('form.upload-excel')[0]);
$.ajax({
type: 'POST',
data: formData,
url: '/Excel/public/upload-excel',
cache: false,
contentType: false,
processData: false,
success: function(data){
if(data.status === 'ok') {
console.log(data.array);
$('#table').DataTable({
colReorder: true,
});
}
}
});
});