Excel Template Generator

Generated Code:
Instructions:
  • Ensure you have installed the Laravel Excel package:
    composer require maatwebsite/excel
  • Add the generated function to your desired controller:
    
                                
                                use Maatwebsite\Excel\Facades\Excel;
    
                                public function {{ functionName }}()
                                {
                                    $data = [[{{ columns }}]];
    
                                    return Excel::download(new class($data) implements \Maatwebsite\Excel\Concerns\FromArray {
                                        private $data;
                                        public function __construct($data) {
                                            $this->data = $data;
                                        }
                                        public function array(): array {
                                            return $this->data;
                                        }
                                    }, '{{ sheetName }}.xlsx');
                                }
                                
                            
  • Ensure the necessary routes are added to `web.php`:
                                Route::get('/download-excel', [YourController::class, '{{ functionName }}'])->name('download.excel');                                                    
  • Access the Excel download function by visiting the route URL in your browser.