DWQA QuestionsCategory: LaravelLaravel excel package!
kandy asked 5 years ago


Step1: compose require maatwebsite/excel: ~2.1.0
Step2: After updating composer, add the ServiceProvider to the providers array in config/app.php


You can use the facade for shorter code. Add this to your aliases:
'Excel' => Maatwebsite\Excel\Facades\Excel::class,

To publish the config settings in Laravel 5 use:

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"
Example :

add this line above to your class
use Excel;

public function getExcel(){
$path = url::to('public/reports');
$file_name = 'report_csv'.time();
$file = Excel::create($file_name, function($excel) {
$excel->sheet('Sheetname', function($sheet) {
$sheet->fromArray( array(
array('fname', 'lname') ,
array('data3', 'data4')
return $file_name;

Thanks :)