我试图访问 laravel collection->each 之外的变量,但我得到..
Undefined variable: headers
这是我的代码:
public function bulkCoding(Request $request) {
Excel::load($request->file, function($reader) {
$headers = $reader->get()->first()->keys();
// Loop through all sheets
$reader->each(function($sheet) {
$headers->each(function ($title) {
dd($title);
});
});
});
}
您需要使用use()
to 在闭包作用域内传递变量 https://stackoverflow.com/a/45366081/1227923:
each(function($sheet) use($headers) {
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)