如何将Laravel Excel存储在邮政编码中
我有一个将Excel文件导出作为计划的作业的类:
class exportExcelBasedOnID {
public function __construct(ScheduleJob $scheduleJob) {
$scheduleJob->processed_at = Carbon::now();
$scheduleJob->processing = true;
$scheduleJob->exception = null;
$scheduleJob->save();
$this->exportExcels($scheduleJob);
}
private function exportExcels(ScheduleJob $scheduleJob) {
$school = $scheduleJob->school;
$payload = unserialize($scheduleJob->payload);
$id = $payload['id'];
$requestUser = User::where('id', $scheduleJob->user_id)->first();
$students = Excels::where('id', $id);
$locale = array_key_exists('locale', $payload) ? $payload['locale'] : \App::getLocale();
//a bunch of code to create the file with format called $final
$final->store('xlsx', storage_path('app/public/EXCEL/'.$school->school_code));
$payload = unserialize($scheduleJob->payload);
$payload['payload'] = $name.'.xlsx';
$scheduleJob->payload = serialize($payload);
$scheduleJob->processed_at = Carbon::now();
$scheduleJob->exception = null;
$scheduleJob->processing = false;
$scheduleJob->save();
}
}
如何将其连接到以下工作然后?
我的邮政编码:
public function export_schedule_zip(School $school, Request $request)
{
$zip = new ZipArchive;
$zipname = 'students.zip';
$zip_folder = 'student';
$zip->open($zipname, ZipArchive::CREATE);
$zip->addEmptyDir($zip_folder);
$zip->close();
return response()->download($zipname);
}
I have a class that exports a excel file as a scheduled job:
class exportExcelBasedOnID {
public function __construct(ScheduleJob $scheduleJob) {
$scheduleJob->processed_at = Carbon::now();
$scheduleJob->processing = true;
$scheduleJob->exception = null;
$scheduleJob->save();
$this->exportExcels($scheduleJob);
}
private function exportExcels(ScheduleJob $scheduleJob) {
$school = $scheduleJob->school;
$payload = unserialize($scheduleJob->payload);
$id = $payload['id'];
$requestUser = User::where('id', $scheduleJob->user_id)->first();
$students = Excels::where('id', $id);
$locale = array_key_exists('locale', $payload) ? $payload['locale'] : \App::getLocale();
//a bunch of code to create the file with format called $final
$final->store('xlsx', storage_path('app/public/EXCEL/'.$school->school_code));
$payload = unserialize($scheduleJob->payload);
$payload['payload'] = $name.'.xlsx';
$scheduleJob->payload = serialize($payload);
$scheduleJob->processed_at = Carbon::now();
$scheduleJob->exception = null;
$scheduleJob->processing = false;
$scheduleJob->save();
}
}
How do I connect it to the following so instead of the excel file being scheduled to download, the excel is stored in a folder called students and zipped and then be scheduled to download afterwards?
My zip code:
public function export_schedule_zip(School $school, Request $request)
{
$zip = new ZipArchive;
$zipname = 'students.zip';
$zip_folder = 'student';
$zip->open($zipname, ZipArchive::CREATE);
$zip->addEmptyDir($zip_folder);
$zip->close();
return response()->download($zipname);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论