I have a function that imports an Excel with the Laravel-Excel library, and within that function in the $ sheet-> every (function ($ row)) {} I am adding the records in an array that I have declared inside the function but outside the $ sheet-> g (), the thing is that then below the whole function I can not use that array to make a return, it is as if it were not declared.
Do you know if there is a specific method or functionality of Laravel Excel to do it?
public function excel($code){
$i = 0;
$transact = array();
$file = File::find($code);
$url = $file->FILE_url;
Excel::selectSheetsByIndex(0)->load($url, function ($sheet) use($i, $transact){
$hoja->each(function ($row) use($i, $transact){
$inCode = $row['inCode'];
$prCode = $row['prCode'];
$transact[$i] = (int)$inCode;
$transact[$i] = (int)$prCode;
$i++;
});
return $transact;
});
}
This way the $ i does not autoincrement and I can not return from $ transact however much I put global ahead.