filmov
tv
#225 Laravel E-commerce | Laravel Excel Export | Export Orders in Laravel (I) | Maatwebsite Laravel
Показать описание
In Part-225 of the Laravel E-commerce series, we will work on the Export feature to export the orders in CSV format.
We will use maatwebsite 3.1 package for the export functionality of orders.
Install Maatwebsite package 3.1 version (if not installed yet) by running the below composer command:-
composer require maatwebsite/excel
1) Create ordersExport
First of all, create ordersExport class by running below artisan command:-
php artisan make:export ordersExport
You can open the ordersExport file in which you can see the collection function automatically created that will return data from the Order model.
2) Create Route:-
// Export Orders
4) Create exportOrders function :-
Now create exportOrders function in OrdersController and write code to download excel file for orders.
6) Add Header Statements:-
Add below statements at the top of OrdersController to include ordersExport that we have created and Maatwebsite class for sure.
use App\Exports\ordersExport;
use Maatwebsite\Excel\Facades\Excel;
7) Update collection function :-
Maatwebsite Package 3.1 does not show column headings by default. We need to take the below steps to add headings for our excel data means the orders table column names so that it will be easier to understand the data.
i) Add below header statement for headings in ordersExport file:-
use Maatwebsite\Excel\Concerns\WithHeadings;
ii) Update ordersExport class in ordersExport file like below :-
class ordersExport implements WithHeadings,FromCollection
iii) Add headings function in ordersExport file with heading names in array as shown in the video.
public function headings(): array{
return['Id','Name','Address','City','State','Country','Pincode','Mobile','Email','Registered on'];
}
In the next video, we will also show ordered products details in orders export to excel.
This video is a part of my Laravel Advance E-commerce Series
Other Popular Stack Developers Series that can help you:-
Follow Stack Developers on Social Media to get updates and resolve your queries
We will use maatwebsite 3.1 package for the export functionality of orders.
Install Maatwebsite package 3.1 version (if not installed yet) by running the below composer command:-
composer require maatwebsite/excel
1) Create ordersExport
First of all, create ordersExport class by running below artisan command:-
php artisan make:export ordersExport
You can open the ordersExport file in which you can see the collection function automatically created that will return data from the Order model.
2) Create Route:-
// Export Orders
4) Create exportOrders function :-
Now create exportOrders function in OrdersController and write code to download excel file for orders.
6) Add Header Statements:-
Add below statements at the top of OrdersController to include ordersExport that we have created and Maatwebsite class for sure.
use App\Exports\ordersExport;
use Maatwebsite\Excel\Facades\Excel;
7) Update collection function :-
Maatwebsite Package 3.1 does not show column headings by default. We need to take the below steps to add headings for our excel data means the orders table column names so that it will be easier to understand the data.
i) Add below header statement for headings in ordersExport file:-
use Maatwebsite\Excel\Concerns\WithHeadings;
ii) Update ordersExport class in ordersExport file like below :-
class ordersExport implements WithHeadings,FromCollection
iii) Add headings function in ordersExport file with heading names in array as shown in the video.
public function headings(): array{
return['Id','Name','Address','City','State','Country','Pincode','Mobile','Email','Registered on'];
}
In the next video, we will also show ordered products details in orders export to excel.
This video is a part of my Laravel Advance E-commerce Series
Other Popular Stack Developers Series that can help you:-
Follow Stack Developers on Social Media to get updates and resolve your queries