Skip to content

Commit

Permalink
Allow custom filename for invoice download
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jul 30, 2019
1 parent 81eb7cd commit 5e655ab
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,23 @@ public function pdf(array $data)
*/
public function download(array $data)
{
$filename = $data['product'].'_'.$this->date()->month.'_'.$this->date()->year.'.pdf';
$filename = $data['product'].'_'.$this->date()->month.'_'.$this->date()->year;

return $this->downloadAs($filename, $data);
}

/**
* Create an invoice download response with a specific filename.
*
* @param string $filename
* @param array $data
* @return \Symfony\Component\HttpFoundation\Response
*/
public function downloadAs($filename, array $data)
{
return new Response($this->pdf($data), 200, [
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
'Content-Disposition' => 'attachment; filename="'.$filename.'.pdf"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
Expand Down

0 comments on commit 5e655ab

Please sign in to comment.