Search code examples
phphttp-redirectlaravelresponse

Redirect and Response on submit Laravel 4


I need a file to download when a form is submitted, however I also want to have the page redirect back to the form with a "form submitted" message.

Obviously something like this wont work:

    return Redirect::to('form')->with('sent', true);
    $downloadLink = base_path().'/something.pdf';
    return Response::download($downloadLink);

Is there a way to do this?

Thanks!


Solution

  • Try this

    $data = array('sent' => true, 'downloadlink' => $downloadlink);
    return Redirect::to('form')->with('data', $data);
    

    if JSON:

    return Response::json(['sent' => true, 'data' => $data']);
    

    to access data in view:

    var_dump($data['sent']), var_dump($data['downloadlink'])