Monday, 26 August 2019

Laravel blade file to word document

I am passing data from my controller to my blade file, and then want to export the blade file to word document, so far things are controlled, I can export blade to word document, the issue is the document is not opening in Microsoft word it says "word found unreadable content in 1.docx". Below is the code that I am using

$view = View::make('advertisement.advt_template.template_dr')->with('advtData', $advtData->first())->render();
$file_name = strtotime(date('Y-m-d H:i:s')) . '_advertisement_template.docx';
$headers = array(
            "Content-type"=>"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "Content-Disposition"=>"attachment;Filename=$file_name"
        );
return response()->make($view, 200, $headers);

  • I am passing data to blade and then storing all information in a variable
  • creating a file name for reference
  • creating headers to be used when downloading file
  • making the response with blade content variable and header information

Any help will be appreciated



from Laravel blade file to word document

No comments:

Post a Comment