title: how to download PDF in laravel 5.4?
body: <p>I'm trying to fetch data from database and pass this data to pdf view and download it.</p>
  
  <p>I tried this code but its not working:</p>
  
  <pre><code>&lt;a href="{{url('/download-PDF/'.$eventData-&gt;id)}}" class="btn btn-danger pull-right"&gt;Download PDF &lt;/a&gt;
  </code></pre>
  
  <p><strong>Route</strong></p>
  
  <pre><code>Route::get('download-PDF/{id}', 'PDFController@pdf');
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>class PDFController extends Controller
  {
  public function pdf($id){
      $getEvent=Event::find($id);
      $eventId=$getEvent-&gt;id;
  
  
      if(isset($eventId)) {
  
          $eventData = Event::where('id', $eventId)-&gt;first();
          $getDays = Day::where('event_id', $eventId)-&gt;get();
          for ($i = 0; $i &lt; count($getDays); $i++) {
              $dayId = $getDays[$i]-&gt;id;
              $schedule[$i] = DaySchedule::where('day_id', $dayId)-&gt;get();
          }
  
      }
  
      $pdf=PDF::loadView('pdf',['eventData' =&gt; $eventData, 'schedule' =&gt; $schedule]);
  
      return $pdf-&gt;download('event.pdf');
  }
  }
  </code></pre>
  
  <p><strong>Config</strong></p>
  
  <pre><code>'providers' =&gt; [
    Barryvdh\DomPDF\ServiceProvider::class,
   ]
  
   'aliases' =&gt; [
   'PDF' =&gt; Barryvdh\DomPDF\Facade::class,
    ]
  </code></pre>