Laravel Datatables Export to PDF File Example
https://www.itsolutionstuff.com/post/laravel-datatables-export-to-pdf-file-exampleexample.html
Last updated
Was this helpful?
https://www.itsolutionstuff.com/post/laravel-datatables-export-to-pdf-file-exampleexample.html
Last updated
Was this helpful?
By Hardik Savani July 4, 2020 Category : LaravelPlayUnmuteLoaded: 0.26%Fullscreen
Hi Dev,
In this quick example, let's see laravel datatables export pdf. you'll learn how to add export pdf button in yajra datatable. This article goes in detailed on laravel yajra datatable pdf export button. step by step explain laravel yajra datatable export buttons pdf.
Here, Creating a basic example of datatables pdf with button in laravel 6, laravel 7, laravel 8 and laravel 9.
In this post, i will show you step by step how to add pdf buttons in Laravel Yajra Datatables. we will use yajra/laravel-datatables-buttons package to adding export button in your datatables. you can easily export table data into pdf file so it can help you to export it.
we need to use snappy for generate pdf file with laravel yajra datatable.
So, let's follow few step to done how to export pdf file from datatable in laravel application.
So let's follow this tutorial and you will get layout as like bellow:
Preview:
Step 1: Install Laravel
In this step, if you haven't laravel application setup then we have to get fresh laravel 7 application. So run bellow command and get clean fresh laravel 7 application.
Step 2 : Install Yajra Datatable
We need to install yajra datatable composer package for datatable and yajra/laravel-datatables-buttons export buttons, so you can install using following command:
After that you need to set providers and alias.
config/app.php
Now you have to run bellow command to get configuration file, so let's run bellow command:
Read Also: Datatable disable sorting on particular column example
Step 3: Install laravel-snappy
Here, we will install laravel-snappy composer package for export data into pdf file. so let's follow few things in this step.
install following dependencies of laravel snappy.
Note : If you have 32-bit system then install this dependencies
Note : If you have 64-bit system then install this dependencies
Now, let's run bellow command to install laravel-snappy composer package:
After that you need to set providers and alias.
config/app.php
Now you have to run bellow command to get configuration file, so let's run bellow command:
Now follow this things:
Note : After copy both folder then give 777 permission
Step 4: Add Dummy Records
In this step, we will create some dummy users using tinker factory. so let's create dummy records using bellow command:
Step 5: Create DataTable Class
Here, we need to create User DataTable class using Yajra Datatable command. so let's run bellow command:
app/DataTables/UsersDataTable.php
Step 6: Add Route
In this is step we need to create route for datatables layout file and another one for getting data. so open your routes/web.php file and add following route.
routes/web.php
Step 7: Create Controller
In this point, now we should create new controller as UserController. this controller will manage layout and getting data request and return response, so put bellow content in controller file:
app/Http/Controllers/UserController.php
Step 8: Create View
In Last step, let's create users.blade.php(resources/views/users.blade.php) for layout and we will write design code here and put following code:
resources/views/users.blade.php
Now we are ready to run our example so run bellow command ro quick run:
Now you can open bellow url on your browser:
Read Also: Laravel Yajra Datatables Export to Excel CSV Button Example
I hope it can help you...
you have created new class file for DataTable. so let's update following file. here we will add display column, buttons and all then things.