In this tutorial, we will learn Laravel 8 PDF, Laravel 8 Generate PDF File using DomPDF

Step 1:

 Install Laravel 8

composer create-project --prefer-dist laravel/laravel blog

Step 2: 

Install dompdf Package

composer require barryvdh/laravel-dompdf


'providers' => [
'aliases' => [
	'PDF' => Barryvdh\DomPDF\Facade::class,

Step 3: 

Add Route routes/web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PDFController;
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
Route::get('generate-pdf', [PDFController::class, 'generatePDF']);

Step 4: 

Add Controller app/Http/Controllers/PDFController.php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PDF;
class PDFController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function generatePDF()
        $data = [
            'title' => 'Welcome to',
            'date' => date('m/d/Y')
        $pdf = PDF::loadView('myPDF', $data);
        return $pdf->download('rathorji.pdf');

Step 5: 

Create View File resources/views/myPDF.blade.php

<!DOCTYPE html>
    <h1>{{ $title }}</h1>
    <p>{{ $date }}</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

May this example help you.