Laravel 10 - Generate PDF using DomPDF in Laravel step by step | Laravel pdf generator tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back so guys in this video we are going to learn about how to generate a PDF using Dom PDF package in larl okay so now guys let's get started so guys let's move to our editor and here we have S the larel application and now guys let us install the Dom PDF package so for that you have to just search for Dom PDF LEL so you'll get a GitHub ring so now guys let us move below at readme.md file and here is a readme guys and now we can get started with the installation so for the installation in LL you can follow this command which is composer require your Dom PDF so let's copy this and get back to our editor and now guys let us paste the command so let's open a new terminal and paste by right click on the mouse and hit enter so now guys let's wait until it get get installed so let me just give a full width perfect so guys our package is successfully installed and now guys let us uh minimize this terminal and let's move inside the config folder you'll be finding an a Dom PDF file so if you don't find that Dom PDF file what you have to do you have to just configure that so for that let's get below and here is the configuration and here is a command guys RT command to publish your Dom PDF file so click on it and copy and now get back right click and paste and hit enter so here you see that your files has been published and now you are able to see that Dom PDF file here okay cool so let's close this and yep now guys you successfully installed the package and setup is done and now let us see with an example how we can generate the PDF file so guys for that let's begin with creating One controller hit the command PHP Artis make colon controller where PDF controller hit enter okay so our controller is created you can find that in app HTTP controller where PDF controller okay and now guys let us create the routes so let's go to our routes web.php so here I create one route route colon using get method and here we'll mention as generate hyphen PDF okay and guys you need to connect to a controller so in the square bracket you have to mention that path of your controller so let me copy my path of this PDF controller so app HTTP controller then your PDF controller so let's paste inside this array and call your PDF controller class and now you have to mention the function name here here like index so on this index blade here it should be lower case I have made it to upper case by mistake and now guys let's copy this index and go to this PDF controller and create the function with the name index public function the function name index or you can create a different function like generate PDF not an issue so let's keep this a unique name like yeah generate PDF okay so it will will be understanding like we are generating a PDF done and now guys to generate the PDF so you can find that code in this uh and here you see guys how we can use it okay so there are load HTML load view so this is loading a blade file type and this is the HTML like you're writing a raw HTML contents and generating in a PDF so we'll be using the load view so for that you can just copy this code and get back paste here and also you have to import the class so you can copy this get back and paste it and now guys let me add some data here like as you have created a variable data so let's tell variable data of array inside array I will tell like let's create a title which is funa in single codes comma fun of web it and then date and get the to-day date so you can use a date function like month date and year and now guys the third call the products here like I have a product data and dollar products variable and here equal to product model colon colon get function so I'm getting all the product details so I have imported the class so if you don't have a product model you can use the user model so you can get the user details okay so guys I have a product model so I'm using this product data and now guys whatever you have stored you are pushing this inside your data variable and insert this PDF load view so guys you need to create a blade file name invoice or you can tell like generate product PDF okay and you can remove this and you can directly create a blade file so for that just go to your resource views inside directly views or go to your any products folder so here I have my products folder and I'm going to create a new file inside that blade. PHP okay hit enter so file is created but here I am insert the product so you have to mention that I'm going inside the products folder Dot and then your blade file okay and now guys let's set up the HTML structure and here you can mention the title dollar title how is this title coming so you are mentioning that here okay so this is the array data you are copying this dollar title and pasting here done so same way you can use h2 tag any tag and paste that dollar title copy and paste and then was your date so you can copy this date and paste here and mention date title okay and then guys if you want uh product detail this is coming in Array format okay you have array of data so you have to Loop that so for that you can use a table doable. table which will be like table bordered and here table head table row where table heading the product ID the product name product price okay let's show this three details only and then guys use a t body so table row and before this table row use a for each Loop to Loop the product details okay so let's copy this products variable and paste here and now you can append this each data like ID so let m control X and paste here oops so here instead of directly pasting you have to add in a TD tag okay and now you can copy and paste the product name and the product price let's save it and now guys uh to use this uh classes you have to include the bootstrap CDN link so how can you do that so let me just copy get bootstrap.css and go to docs so here we have a CDN link of CSS let's copy that and paste here yep and now Guys these are few extra lines you can just remove this so make sure you are keeping this R style so it will load correctly okay now you can download this PDF yep let's go back and make sure your code is correct and here guys you want to generate as different name like um funa product data.pdf okay so this will be the downloading file name and now you can get back to the web.php and let's copy this so yep go to your browser and from anywhere you can just paste that URL generate PDF it will download that PDF whatever you have given in that function okay hit enter so it will just download it so here you see it's downloaded let me open it cool so guys we have successfully generated the PDF and given the correct data and looped all the products so these product details are here let me just show you inside my products table and these are the details guys okay done okay so now guys if you want to append more details like adding your user details also let me just give command paste here and add it to users and here we change the variable as user let's create a variable user equal to your user model col col get function and you can get this user data also and just Loop there so let me just copy this and paste below and before that I want to give a horizontal row HR and then you can start appending here like name and email okay and now let's change it to users so make sure you are copying this correct data here and we are seeing error guys okay it's not imported let's import the class user model so yep our class is imported user model get back and now you are appending this user data and just check here user data name and and email okay and now guys let's try to generate a new PDF so generate hyphen PDF hit enter so you see that again new file has been done and here you see guys perfect and guys coming back to your uiux like designing this table View and making as a invoice format or any other format you can just use the uh CSS codes directly inside your head tag and utilize it okay so guys in this video that's it we have successfully learned how to generate the PDF using Dom PDF in LL so thank you for watching this video guys please subscribe like and share
Info
Channel: Funda Of Web IT
Views: 6,579
Rating: undefined out of 5
Keywords: fundaofwebit, laravel 10 generate pdf, laravel pdf generator tutorial, laravel 8 pdf generator tutorial, generate pdf in laravel, how to generate pdf in laravel, how to generate pdf in laravel 9 with dompdf, generate pdf in laravel 10 with dompdf, laravel dompdf tutorial, laravel 10 dompdf, dompdf laravel 10, barryvdh/laravel-dompdf, laravel 10 tutorail generate pdf funda
Id: 919OCLKM-jU
Channel Id: undefined
Length: 11min 16sec (676 seconds)
Published: Sat Jan 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.