Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoice download can change file name #715

Closed
4UForever opened this issue Jul 25, 2019 · 3 comments
Closed

Invoice download can change file name #715

4UForever opened this issue Jul 25, 2019 · 3 comments

Comments

@4UForever
Copy link

Could you please allow to change file name (.pdf) in download invoice or can I custom the name of the download file, Now it's like fixed file name .
https://github.com/laravel/cashier/blob/9.0/src/Invoice.php#L269

many thanks.

@Sti3bas
Copy link

Sti3bas commented Jul 26, 2019

@4UForever download method returns Response object, so you can just change a header:

use Illuminate\Http\Request;

Route::get('user/invoice/{invoice}', function (Request $request, $invoiceId) {
    $response = $request->user()->downloadInvoice($invoiceId, [
        'vendor'  => 'Your Company',
        'product' => 'Your Product',
    ]);

    $filename = 'custom.pdf';

    $response->headers->set('Content-Disposition', 'attachment; filename="'.$filename.'"');

    return $response;
});

@4UForever
Copy link
Author

@Sti3bas many thanks for your advise and your sample code is so helpful for me. :)

@driesvints
Copy link
Member

I've sent in a PR for this here: #723

jfrabaute added a commit to jfrabaute/cashier that referenced this issue Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants