Skip to content
Advertisement

export excel with a query using maatwebsite with laravel [closed]

Hello i’m really new using maatwebsite already read the documentation but cant find it, can someone give me an idea about executing query after exporting excel using maatwebsite? here is my code :

public function export()
{
    Excel::download(new KodePosExport, 'KodePos.xlsx');
    KodePos::query()->truncate();
    return redirect('/')->with('success', 'All good!');
}

it’s able redirect to the page that i wanted and truncate the data but not exporting the excel, how can i do it? Thank you

If using this function exporting excel working perfectly, but not query included

public function export()
{
    return Excel::download(new KodePosExport, 'KodePos.xlsx');
    //KodePos::query()->truncate();
    // return redirect('/')->with('success', 'All good!');
}

Advertisement

Answer

$download = Export::download(...);

KodePos::query()->truncate();

return $download;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement