Alfie Mellor

Alfie Mellor

1650696172

How to Generate a PDF File in Laravel 9 with DomPDF

I will give you a simple example of how to generate a pdf file in laravel 9. we will use DomPDF composer package to generate a pdf file in laravel 9. just follow the below step and get a simple pdf using laravel 9.

Step 1: Install Laravel 9

This step is not required; however, if you have not created the laravel app, then you may go ahead and execute the below command:

composer create-project laravel/laravel example-app

Step 2: Install DomPDF Package

next, we will install DomPDF package using following composer command, let's run bellow command:

composer require barryvdh/laravel-dompdf

Step 3: Create Controller

In this step, we will create PDFController with generatePDF() where we write code of generate pdf. so let's create controller using bellow command.

php artisan make:controller PDFController

in PDFController, we also get users table data and display them into pdf file. so you can add some dummy data on the users table by using the following tinker command:

php artisan tinker

User::factory()->count(10)->create()

Now, update the code on the controller file.

app/Http/Controllers/PDFController.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Models\User;
use PDF;
  
class PDFController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function generatePDF()
    {
        $users = User::get();
  
        $data = [
            'title' => 'Welcome to codequs.com',
            'date' => date('m/d/Y'),
            'users' => $users
        ]; 
            
        $pdf = PDF::loadView('myPDF', $data);
     
        return $pdf->download('codequs.pdf');
    }
}

Step 4: Add Route

Furthermore, open routes/web.php file and update code on it.

routes/web.php

<?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 5: Create View File

In Last step, let's create myPDF.blade.php(resources/views/myPDF.blade.php) for layout of pdf file and put following code:

resources/views/myPDF.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 9 Generate PDF Example - codequs.com</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
    <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.</p>
  
    <table class="table table-bordered">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
        </tr>
        @foreach($users as $user)
        <tr>
            <td>{{ $user->id }}</td>
            <td>{{ $user->name }}</td>
            <td>{{ $user->email }}</td>
        </tr>
        @endforeach
    </table>
  
</body>
</html>

Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve

Now, Go to your web browser, type the given URL and view the app output:

http://localhost:8000/generate-pdf

I hope it can help you...

#laravel #laravel9 #php #pdf #programming 

What is GEEK

Buddha Community

How to Generate a PDF File in Laravel 9 with DomPDF

Laravel 8 PDF Generate Example

Today, we will see Laravel 8 PDF Generate Example.

For generating PDF file we will use Laravel-dompdf package, it is create pdf file and also provide to download file functionalities it is very easy to generate pdf in laravel 8, i will give you example in very simple way to generate pdf file and download in your system.

So, Let’s start and see how to generate pdf in laravel 8.

Laravel 8 PDF Generate Example

https://websolutionstuff.com/post/laravel-8-pdf-generate-example


Read Also : Send Mail Example In Laravel 8

https://websolutionstuff.com/post/send-mail-example-in-laravel-8


Read Also : How To Generate QRcode In Laravel

https://websolutionstuff.com/post/how-to-generate-qrcode-in-laravel


Read Also : How To Generate Barcode In Laravel

https://websolutionstuff.com/post/how-to-generate-barcode-in-laravel

#laravel 8 pdf generate example #laravel 8 #pdf generate #generate pdf in laravel 8 #laravel-dompdf package #how to generate pdf in laravel 8

I am Developer

1597559012

Multiple File Upload in Laravel 7, 6

in this post, i will show you easy steps for multiple file upload in laravel 7, 6.

As well as how to validate file type, size before uploading to database in laravel.

Laravel 7/6 Multiple File Upload

You can easily upload multiple file with validation in laravel application using the following steps:

  1. Download Laravel Fresh New Setup
  2. Setup Database Credentials
  3. Generate Migration & Model For File
  4. Make Route For File uploading
  5. Create File Controller & Methods
  6. Create Multiple File Blade View
  7. Run Development Server

https://www.tutsmake.com/laravel-6-multiple-file-upload-with-validation-example/

#laravel multiple file upload validation #multiple file upload in laravel 7 #multiple file upload in laravel 6 #upload multiple files laravel 7 #upload multiple files in laravel 6 #upload multiple files php laravel

Waylon  Bruen

Waylon Bruen

1617619860

Laravel DOM PDF - How to Generate PDF in Laravel 8 Using DOM PDF

In Laravel, you have access to third-party packages because of the composer. Using composer, you can install any package in Laravel. The composer provides the package dependencies in PHP. Here, we’ll be talking about the Laravel DOM PDF . This is an open-source package available on Github to generate the PDF. By using this package, you can easily generate the PDF in Laravel. In this post, Iwill be implementing the feature to export the content as a PDF in Laravel 8. So, PDF stands for portable document format . It helps us for providing the invoices, user manuals, eBooks, application forms, etc. So, let’s start by creating a new project in Laravel 8.

Contents

  • 1 Prerequisites
  • 2 Create New Project For Laravel DOM PDF
  • 3 Create and Configure Database
  • 4 Install Laravel DOM PDF Package
  • 5 Configure DOM PDF Package in Laravel 8
  • 6 Create Model and Migration
  • 7 Create Factory Class For User Table
  • 8 Insert Dummy Records Using Tinker
  • 9 Create a Controller For Laravel 8 DOM PDF
  • 10 Add Routes For Generating PDF
  • 11 Create Views
  • 12 Conclusion
  • 12.1 Share this:
  • 12.2 Like this:
  • 12.3 Related

Prerequisites

To start the Laravel 8 project, you will require the following tools configured in your system.

  • PHP >= 7.3
  • MySQL (version > 5)
  • Apache/Nginx Server
  • VS Code Editor
  • Composer

#laravel 8 #laravel create pdf file #laravel pdf #laravel

How To Delete File From Public Folder In Laravel

In this post we will see how to remove/delete file from public storage, today I will give you demo how to remove file from storage folder in laravel.

So, here I will explain how to delete image from storage folder using Laravel File System and php function file_exists() and unlink().

How To Delete File From Public Folder In Laravel

https://websolutionstuff.com/post/how-to-delete-file-from-public-folder-in-laravel

#how to delete file from public folder in laravel #laravel #php #file #how to delete file from storage folder in laravel #laravel 6 remove file from public folder

I am Developer

1597817005

Bar Code Generator In Laravel 7.x

Bar Code Generate in Laravel 7, 6. In this post, i will show you simple and easy steps to generate bar/qr code in laravel.

Generate Bar codes in Laravel

Use the below given steps and generate bAR/QR codes in laravel Projects:

  1. Install Laravel Fresh Setup
  2. Set database Credentials In .env File
  3. Install simple-QRcode Package
  4. Register Package
  5. Test Qr Code
  6. Conclusion

https://www.tutsmake.com/laravel-6-simple-generate-or-create-qr-codes-example/

#laravel 7 bar code generator #barcode generator laravel 7 #barcode generator laravel 6 #laravel 7 qr code generator #laravel simple/barcode example