►Laravel 9 Tutorial from the beginning:- [ Ссылка ]
In Part-188 of the Laravel 10 series, we will export Subscribers emails to Excel (CSV) format with the header.
We will install and use maatwebsite 3.1 package for the export functionality of subscribers.
Install Maatwebsite package 3.1 version by running below composer command:-
composer require maatwebsite/excel
1) Create subscribersExport
First of all, create a subscribersExport class by running below artisan command:-
php artisan make:export subscribersExport
You can open the subscribersExport file in which you can see the collection function automatically created that will return data from the NewsletterSubscriber model.
2) Create Route:-
Now create a Get route to export subscribers in the web.php file like below:-
Route::get('export-subscribers','NewsletterController@exportSubscribers');
3) Update subscribers.blade.php file :-
Now update the subscribers.blade.php file to add the export subscribers link.
4) Create exportSubscribers function:-
Now create the exportSubscribers function in NewsletterController and write code to download Excel file for subscribers.
5) Add Header Statements:-
Add the below statements at the top of NewsletterController to include subscribersExport that we have created and Maatwebsite class for sure.
6) Update subscribersExport.php file:-
Now we will update the collection function in the subscribersExport.php file to write a query to select subscribers that are active only.
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 newsletter_subscribers table column names so that it will be easier to understand the data.
i) Add below header statement for headings in subscribersExport file:-
use Maatwebsite\Excel\Concerns\WithHeadings;
ii) Update subscribersExport class in subscribersExport file like below:-
class subscribersExport implements WithHeadings, FromCollection
iii) Add headings function in subscribersExport file with heading names in array as shown in the video.
►Laravel 9 Tutorial Playlist (Create Multi-Vendor E-commerce Website) - [ Ссылка ]
►Click here to subscribe for Laravel & other updates - [ Ссылка ]
Popular Stack Developers Series that can help you:-
►React JS Tutorial for Beginners with Laravel 9 - [ Ссылка ]
►Laravel Tutorial for Beginners - [ Ссылка ]
►GIT Tutorial for Beginners - [ Ссылка ]
►Laravel API Tutorial - [ Ссылка ]
►Laravel Interview Questions - [ Ссылка ]
►jQuery Tutorial - [ Ссылка ]
►Laravel Basic E-commerce Series - [ Ссылка ]
►Laravel Dating Series - [ Ссылка ]
►Join this channel to get the complete source code of all series:
[ Ссылка ]
Follow Stack Developers on Social Media to get updates and resolve your queries
►Like Facebook Page to get updates - [ Ссылка ]
►Join Facebook Group to resolve your queries - [ Ссылка ]
►Follow on Instagram - [ Ссылка ]
►Follow on GitHub - [ Ссылка ]
#laravel9 #laravel9tutorial #laravel
Ещё видео!