If you want to change a value of a variable within a closer function, use the &
before each variable.
1 2$roles = [];3 4$users->each(function ($user) use ($roles) {5 $roles = $user->roles;6});
Output
1// [] empty array
Use the &
before the variable.
1$users->each(function ($user) use ($roles) {2 $roles = $user->roles;3});
Output
1// array of rules