Reputation: 361
I have done the same thing before, however faced with an error on this code:
Excel::create('churros_contact', function($excel){
$excel->sheet('contact', function($sheet){
$sheet->fromModel(Contact::all());
});
})->export('xlsx');
It says :
ZipArchive::close(): Failure to create temporary file: No such file or directory
Where can I modify the directory setting? As for permission, I already set it, so it should be other issues.. What config might I have missed out?
If I change to XLS, it doesn't give me error, but it also doesn't download.
Upvotes: 2
Views: 2037
Reputation: 589
public function csvOrderstatus($id)
{
$result = DB::table('order')->where('id',$id)->first(); // the data you want to download as csv
$csv = (array)$result; // stored the data in a array
return Excel::create('csvfile', function ($excel) use ($csv) {
$excel->sheet('mySheet', function ($sheet) use ($csv) {
$sheet->fromArray($csv);
});
})->download('xls');
}
This works for me. Hope this will help you.
Upvotes: 4