2
votes

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.

1
maybe you are missing some php extensions if that is a new machine? but if you use homestead then it shouldn't matterlewis4u
well, this is in my localhost, and in previous project, i used the same thing, but nothing went wrongBrian Ruchiadi
@lewis4u : I have yet to find the solution. As i wondering where the error is, do you have any clue? Thank you beforeBrian Ruchiadi

1 Answers

4
votes
 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.