title: how to define a named route and download a file from database in laravel
body: <p>I have my url defined in blade as:</p>
  
  <pre><code>href="/finance/invoices/download/{{ $invoice-&gt;file_path }}"
  </code></pre>
  
  <p>and the route in web.php is:</p>
  
  <pre><code>Route::get('invoices/download/{year}/{month}/{file}', 'InvoiceController@download');
  </code></pre>
  
  <p>my file is stored in the database as:</p>
  
  <pre><code>2018/07/invoiceberry_invoice_template_1.docx
  </code></pre>
  
  <p>edit function in my controller is:</p>
  
  <pre><code>public function edit(Invoice $invoice)
  {
      $projectStageBillings = $invoice-&gt;projectStageBillings;
  
      $projectStageBilling = $projectStageBillings-&gt;first();
      $client = $projectStageBilling-&gt;projectStage-&gt;project-&gt;client;
      $client-&gt;load('projects', 'projects.stages', 'projects.stages.billings');
  
      $billings = [];
      foreach ($projectStageBillings as $key =&gt; $billing) {
          $billing-&gt;load('projectStage', 'projectStage.project');
          $billings[] = $billing;
      }
  
      return view('finance.invoice.edit')-&gt;with([
          'invoice' =&gt; $invoice,
          'clients' =&gt; Client::select('id', 'name')-&gt;get(),
          'invoice_client' =&gt; $client,
          'invoice_billings' =&gt; $billings,
  
      ]);
  }
  </code></pre>
  
  <p>and download method is :</p>
  
  <pre><code>public function download($year, $month, $file, $inline = true)
  {
      $headers = [
          'content-type' =&gt; 'application/pdf',
      ];
  
      $file_path = FileHelper::getFilePath($year, $month, $file);
  
      if (!$file_path) {
          return false;
      }
  
      if ($inline) {
          return Response::make(Storage::get($file_path), 200, $headers);
      }
  
      return Storage::download($file_path);
  }
  </code></pre>
  
  <p>how do I get url of my file and download it?</p>