I have a Laravel ->each()
function inside a loop.
I want to be able to get at the loop variables from within the each function.
foreach ($stringsArray as $string) {
if (!empty($string)) {
DBModel::all()->each(function (DBModel $model) {
global $string;
// $string at this point is nothing/undefined
How can I access $string
from within the ->each()
function?
This is using laravel 4.2.
With the current code $string
is undefined (with or without the global
directive).