File Download with Laravel 5.3

1

I need to make PDF files available for download. I do not know if I'm at least on the right track, but I'm having an error that indicates that the file does not exist. My controller looks like this:

public function  download($id,Request $request)
{
    $title = 'Download - file';
    if($request->ajax())
    {
        return URL::to('file/'. $id . '/download');
    }
    $file = File::findOrfail($id);
    $fileNome = $file->nome;
    $dir= public_path()."\$file->user_id\$fileNome";
    $headers = array(
      'Content-Type: application/pdf',
      );
    $baixar = Response::download($dir, $fileNome, $headers);
    return view('file.download',compact('title','baixar'));
}

The error is:

  

FileNotFoundException in File.php line 37: The file   "C: \ xampp \ htdocs \ puntualContabi \ public \ 1 \ boleto_cassio.pdf" does not   exist in File.php line 37 at   File-> construct ('C: \ xampp \ htdocs \ puntualContabi \ public \ 1 \ boleto_cassio.pdf')   in BinaryFileResponse.php line 94

The file path is correct. I do not understand the reason for this error. Can anyone help?

    
asked by anonymous 15.12.2016 / 16:27

0 answers