Professional Documents
Culture Documents
6 Astuces Pour Améliorer L'expérience Utilisateur de Votre Site Web (UX)
6 Astuces Pour Améliorer L'expérience Utilisateur de Votre Site Web (UX)
6 Astuces Pour Améliorer L'expérience Utilisateur de Votre Site Web (UX)
// web.php
Route::get('disneyplus/list', 'DisneyplusController@index')->name(
'disneyplus.index');
Now, create a view file called list.blade.php file. Add the following code.
@extends('layout')
@section('content')<table class="table table-striped">
<thead>
<th>ID</th>
<th>Show Name</th>
<th>Series</th>
<th>Lead Actor</th>
<th>Action</th>
</thead>
<tbody>
@foreach($shows as $show) <tr>
<td>{{$show->id}}</td>
<td>{{$show->show_name}}</td>
<td>{{$show->series}}</td>
<td>{{$show->lead_actor}}</td>
</tr>
@endforeach </tbody>
</table>
@endsection
Now, add the code inside the index() function of DisneyplusController.php file.
// web.php
Route::get('/downloadPDF/{id}','DisneyplusController@downloadPDF');
Now, update the list.blade.php file and add the Download PDF link.
@extends('layout')
@section('content')<table class="table table-striped">
<thead>
<th>ID</th>
<th>Show Name</th>
<th>Series</th>
<th>Lead Actor</th>
<th>Action</th>
</thead>
<tbody>
@foreach($shows as $show) <tr>
<td>{{$show->id}}</td>
<td>{{$show->show_name}}</td>
<td>{{$show->series}}</td>
<td>{{$show->lead_actor}}</td>
<td><a href="{{action
('DisneyplusController@downloadPDF', $show->id)}}">Download PDF</a></td>
</tr>
@endforeach </tbody>
</table>
@endsection
Okay, inside the views folder, create one file called pdf.blade.php file and add the following code.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<table class="table table-bordered">
<thead>
<tr>
<td><b>Show Name</b></td>
<td><b>Series</b></td>
<td><b>Lead Actor</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>
{{$show->show_name}}
</td>
<td>
{{$show->series}}
</td>
<td>
{{$show->lead_actor}}
</td>
</tr>
</tbody>
</table>
</body>
</html>
We have created a simple table which will be generated inside the PDF.
// DisneyplusController.php
public function downloadPDF($id)
{
$show = Disneyplus::find($id); $pdf = PDF::loadView('pdf'
, compact('show'
));
return $pdf->download('disney.pdf'
);}
You will see that it downloads the PDF file and open that PDF, you will see the table contains show listings.
Conclusion
This was the simple example of Laravel 6 Generate PDF. Finally, our tutorial on How to Generate PDF
in Laravel 6 is over.