Skip to content

Best practice for documents download #2491

Answered by tabuna
lrnzfrr asked this question in Q&A
Discussion options

You must be logged in to vote

If you want the "Download" button to be on several screens at once, but execute code as the click was only in one place, there are several ways:

  • Use screen inheritance.
  • Give the button a formaction instead of a method

If you just want to pass a parameter, it would be like this:

Button::make('Export file')
    ->method('export', [
        'name' => "Any name for file",
    ])
    ->icon('cloud-download')
    ->rawClick()
    ->novalidate(),

and method screen:

/**
 * @return \Symfony\Component\HttpFoundation\StreamedResponse
 */
public function export($name)
{
    return response()->streamDownload(function () {
        $csv = tap(fopen('php://output', 'wb'), function ($csv) {
            f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lrnzfrr
Comment options

Answer selected by lrnzfrr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants