Laravel 5.5 export excel

How to export excel in laravel and which library is best for laravel 5.5.
Deepak Sharma
Asked 02-11-2019
37

Answer (1)
First thing need to do i.e install Laravel maatwebsite package for use Excel facade. Just run command as below in composer or girhub bash composer require maatwebsite/excel Then open config/app.php <?php return [....     'providers' => [....         Maatwebsite\Excel\ExcelServiceProvider::class,     ],     'aliases' => [ ....         'Excel' => Maatwebsite\Excel\Facades\Excel::class,     ],    .... And at last here is code for export
create new method for controller.
/** * Create a new controller instance. * * @return void */ public function exportFile($type){ $products = Product::get()->toArray(); return \Excel::create('download_excel_demo', function($excel) use ($products) { $excel->sheet('sheet name', function($sheet) use ($products) { $sheet->fromArray($products); }); })->download($type); }
Deepak Sharma
Asked 17-08-2019
45 Likes
Comments
Write comment

Submit your answer