【发布时间】:2016-06-11 23:37:45
【问题描述】:
我已经为 laravel 安装了 maatwebsite/excel 包。它工作正常。我的问题是我检查文件后如何处理它。
我显示到文件论坛和上传文件的上传()函数在这里:
public function upload(Request $request) {
$orientation = $request->get('orientation');
if($request->file('file')) {
$status = Excel::load(Input::file('file'), function ($reader) use ($orientation) {
return self::upload_excel_files($reader, $orientation);
});
if($status) {
Session::flash('status', "Excel data was imported successfully");
return redirect(route('admin.exchange.upload'));
}
else {
return redirect(route('admin.exchange.upload'))->withErrors('Invalid format. Please check the XLS template.');
}
}
return view('admin.exchange.upload');
}
public function upload_excel_files($file, $orientation) {
if(something) return true;
else return false;
}
upload_excel_files 函数检查文件是否具有正确的格式,如果是,它会处理它并且必须返回一个成功的注释。如果文件与要求格式不匹配,则需要给出错误消息。
不幸的是,我不确定将用户消息放在哪里。与示例中一样,它始终返回成功消息。如果由于某种原因消息在 upload_excel_files() 函数中,我没有通过第一次重定向得到消息,我在第二次重定向时得到它,这很奇怪。
你们会推荐我做什么?
【问题讨论】:
标签: php excel laravel laravel-5.2