title: Laravel 8 upload and download file
body: <p>I am trying to put a download button within a dataTable in Laravel but am getting the following error: &quot;DataTables warning: table id=dataTableBuilder - Exception Message: Undefined variable: fileName&quot;.</p>
  <p>This is my ReportController snippet:</p>
  <pre><code>
  public function store(CreateReportRequest $request)
      {
          $request-&gt;validate([
              'file_path' =&gt; 'required|mimes:pdf|max:2048'
              ]);
      
          $report = new Report;
              if($request-&gt;file()) {
                  $fileName           = time().'_'.$request-&gt;file_path-&gt;getClientOriginalName();
                  $filePath           = $request-&gt;file('file_path')-&gt;storeAs('reports', $fileName, 'public');
                  $report-&gt;name          = time().'_'.$request-&gt;file_path-&gt;getClientOriginalName();
                  $report-&gt;file_path     = '/storage/' . $filePath;
                  $report-&gt;save();
                  Flash::success('Pop saved successfully.');
              }
  
          return redirect(route('reports.index'));
      }
  
      public function download($fileName)
      {
              $file_path = storage_path('reports') . &quot;/&quot; . $fileName;
              return Response::download($file_path);
      }
  </code></pre>
  <p>This is my view snippet (button for the download):</p>
  <pre><code>    &lt;a href=&quot;{{ route('reports.download', $fileName) }}&quot; class='btn btn-ghost-info'&gt;
         &lt;i class=&quot;fa fa-download&quot;&gt;&lt;/i&gt;
      &lt;/a&gt;
  </code></pre>
  <p>And this is my routes snippet:</p>
  <pre><code>    Route::post('/reportdownload/{fileName}', [App\Http\Controllers\ReportController::class, 'download'])-&gt;name('reports.download');
  </code></pre>
  <p>Please help me figure out what I am doing wrong.</p>