Answer the question
In order to leave comments, you need to log in
How to export to excel on laravel?
Hello! Unable to export excel file to Laravel. I use the maatwebsite / excel library, I do it as in the documentation through the export method, it tries to send the headers, but then an error occurs - the headers have already been sent. Enter action code in controller
public function excel()
{
$filename = 'excel_export'.time();
Excel::create($filename, function($excel){
$excel->sheet('first tab', function($sheet){
$callsQuery = DB::table('calls');
$calls = $callsQuery->get();
$sheet->loadView('home.first', array('calls' => $calls));
});
})->export('xls');
}
Answer the question
In order to leave comments, you need to log in
Check if there is a random space before the <?php tag and if the output functions are called in some middleware
Google "maatwebsite/excel headers already sent", first result, "call string() instead of export() then wrap up result in your response"
If that doesn't work, google further.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question