6 Astuces Pour Améliorer L'expérience Utilisateur de Votre Site Web (UX)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

6 astuces pour améliorer l'expérience utilisateur

de votre site Web (UX)


Lieu : 5, rue Gay60 613 Pires
Indicateur : Excellent

Step: 8 Create a view file for display the data.


Before we create a view file, we need to add one route inside the web.php.

// 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.

public function index()


{
$shows = Disneyplus::all();
return view('list', compact('shows'
));}

Now, go to the http://laravel6.test/disneyplus/list or http://localhost:8000/disneyplus/list

You will see the listing of the shows.

Step: 9 Create a route to download the pdf file


Add the following code inside the route 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

Step: 10 Create pdf.blade.php file to design our pdf


You can create the new DOMPDF instance and load an HTML string, file, or blade view name. You can
save it to the file, or stream.

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.

Step: 11 Write a controller function to download the PDF


Write the following code inside the DisneyplusController.php file.

// DisneyplusController.php
public function downloadPDF($id)
{
$show = Disneyplus::find($id); $pdf = PDF::loadView('pdf'
, compact('show'
));
return $pdf->download('disney.pdf'
);}

Now, go to the http://laravel6.test/disneyplus/list or http://localhost:8000/disneyplus/list and click on the


Download PDF link.

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.

You might also like