Step 1 : Install Laravel using the following command.
composer create-project --prefer-dist laravel/laravel laravelPDF
composer require barryvdh/laravel-dompdf
'providers' => [
Barryvdh\DomPDF\ServiceProvider::class,
],
'aliases' => [
'PDF' => Barryvdh\DomPDF\Facade::class,
],
php artisan make:auth
php artisan make:controller PDFController
Route::get('users','PDFController@index');
@extends('layouts.app')
@section('content')
<div class="col-md-12 table_center">
<div class="col-md-10">
<table class="table table-striped">
<thead>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td><a class="btn btn-success" href="{{url('downloadPDF/'.$user->id)}}">Download</a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
public function index()
{
$users = User::get();
return view('users', compact('users'));
}
Route::get('downloadPDF/{id}','PDFController@downloadPDF');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<table class="table table-bordered">
<thead>
<tr>
<td><b>ID</b></td>
<td><b>Name</b></td>
<td><b>Email</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
</tr>
</tbody>
</table>
</body>
</html>
use App\User; use Illuminate\Http\Request; use PDF;
public function downloadPDF($id) {
$user = User::find($id);
$pdf = PDF::loadView('pdf', compact('user'));
return $pdf->download('disney.pdf');
}