Skip to content

Commit

Permalink
Merge pull request #723 from laravel/download-as
Browse files Browse the repository at this point in the history
[10.0] Allow custom filename for invoice download
  • Loading branch information
taylorotwell authored Jul 30, 2019
2 parents 81eb7cd + 5e655ab commit d92f6a3
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 d92f6a3

Please sign in to comment.