I am using Angular 4 in my Front end and Laravel 5.2 in my backend.I want to import an Excel sheet from UI, store the values in DB, retrieve the values and show them in UI using Angular.
I am using Maatwebsite/Excel package in laravel for this. My excel sheet has the following structure.
name | details | price
expertphp | Online Tutorials | 100
hello | code | 200
My laravel code is as below: Here myFile is the key which has the file path and name as its value.
$File = $request->file('myFile');
$path = $request->file('myFile')->getRealPath();
$real_name = $File->getClientOriginalName();
$data = Excel::load($path)->get();
if($data->count()){
foreach($data as $key => $value){
$arr[] = ['name' => $value->name, 'details' => $value->details, 'price' => $value->price];
}
}
return response()->success($data);
I get my reponse as below:
{
"errors":false,
"data":[
{
"namedetailsprice":"expertphp\tOnline tutorials\t100"
},
{
"namedetailsprice":"hello\tfirst code\t2000"
}
]
}
I am not understanding why is the headers becoming one field. Appreciate any help.
Thanks.