Solved it by first calling the stored method then use Response::download to reference the created file on the server.
Laravel Administrator and Laravel Excel, CSV and XLS export
Hi,
Not sure if this is the right place, currently I'm building a excel and csv export feature into Laravel Administrator as a global action for my models so naturally I picked up upon Laravel Excel, however for reasons I'm not clear why I just couldn't get the download working. Here is my code under my model global_action config
'download_excel' => [
'title' => 'Download CSV',
'messages' => [
'active' => 'Creating the csv...',
'success' => 'CSV created! Downloading now...',
'error' => 'There was an error while creating the csv',
],
//the Eloquent query builder is passed to the closure
'action' => function($query)
{
//get all the rows for this query
$data = $query->get();
//do something to put it into excel
Excel::create('classess', function ($excel) use ($data) {
// Set sheets
$excel->sheet('first sheet', function ($sheet) use ($data) {
// Sheet manipulation
$sheet->fromArray($data);
});
})->export('csv');
}
],
This was the same as how http://www.maatwebsite.nl/laravel-excel/docs/export described on how to start a download export. Am I missing out on anything?
Laravel Administrator docs can be found at
http://administrator.frozennode.com/docs/model-configuration#global-custom-actions
Please or to participate in this conversation.