From 5e655ab8601ee7eaf47fd07bee7e7f833dd2a222 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 30 Jul 2019 15:19:30 +0200 Subject: [PATCH] Allow custom filename for invoice download --- src/Invoice.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Invoice.php b/src/Invoice.php index e1f97a11..b2d202f3 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -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', ]);