1

I have below function to download a pdf file

public function download($id) {
        $detail = pesanmakam::findOrFail($id);
        $name = date('YmdHis') . ".pdf";
        $data = PDF::loadView('guest/log/pdf', compact('detail'))->setPaper('a4')->setWarnings(false)->save('myfile.pdf');
        return $data->download($name);
    }

above download function works fine but it's just stay on the same page. Is it possible to redirect it to another page after the download succeed?

Moby M
  • 910
  • 2
  • 7
  • 26

4 Answers4

1

You can't because forcing download file is made with HTTP header and redirection is based on the same. So you can't do both at the same time.

You can find more information on this other topic here

slig36
  • 187
  • 3
  • 13
0

Read it

public function download($id) {
        $detail = pesanmakam::findOrFail($id);
        $name = date('YmdHis') . ".pdf";
        $data = PDF::loadView('guest/log/pdf', compact('detail'))->setPaper('a4')->setWarnings(false)->save('myfile.pdf');
       // return $data->download($name);
        return Redirect::to($url);//$url > where u want to go
    }
Minar Mnr
  • 1,376
  • 1
  • 16
  • 23
0

Paste the following line just after the function call

header('Location: http://www.example.com/');

suppose you called function like

$down = download(10);
//then just below it write like
header('Location: http://www.example.com/');

instead of http://www.example.com put the page url where you want to redirect after download.

Salman Mohammad
  • 182
  • 1
  • 14
0

Try this:

public function download($id) {
        $detail = pesanmakam::findOrFail($id);
        $name = date('YmdHis') . ".pdf";
        $data = PDF::loadView('guest/log/pdf', compact('detail'))->setPaper('a4')->setWarnings(false)->save('myfile.pdf');
        $data->save('folder_name/'.$name)
        return Redirect::to('url')
    }
Nikita
  • 437
  • 2
  • 12