Excel 移动到 Laravel 中的另一条路线后下载停止

Excel download stops by moving to another route in Laravel

使用 maatwebsite-excel 库,我在 Laravel 应用程序中将数据导出为 Excel 文件。如果数据量很大,导出过程需要几秒钟才能完成。同时,如果我单击任何其他菜单选项卡并移至新路径(应用程序中的任何其他页面),下载过程将停止。 我想知道我是不是做错了什么,或者情况就是这样。我看到一些网站具有下载功能(不一定 Excel/CSV),但当我转到其他页面时它们会继续下载。 这是我的代码片段:

Excel::create('Groups', function ($excel) use ($group_set_data) {
        foreach ($group_set_data as $group_set) {
            $counter = 2;
            $excel->sheet($group_set['name'], function ($sheet) use ($group_set, $counter) {
                $sheet->row(1, [
                    'Student',
                    'ID',
                    'grade',
                    'Group Name',
                ]);

                foreach ($group_set['groups'] as $key => $value) {
                    $users = Group::get_users_by_group_id($value['id']);
                    foreach ($users as $user) {
                        $sheet->row($counter, [
                            $user['name'],
                            $user['id'],
                            $user['grade'],
                            $value['name'],
                        ]);
                        $counter++;
                    }
                }
            });
        }
    })->export('xls');

记住函数 'excel::create..... your code here ...' 在控制器内部的函数中,所以你需要在完成函数时显示最终路径

这是我的代码:

    $msj = "Upload succesfull"; $class = "alert alert-success";

/* ============================  END  ============================ */ 
})->export('xls'); // end read excel::function

return back()->with([]);

}

希望对你有所帮助