I need to send email to more than one person, for this I've created a for
replay structure, but I'm getting my variable undefined.
I tried something like:
public function avisarAnjos(Request $request)
{
$usuariosAnjos = User::select('email')
->where('usuario_anjo', 1)
->get();
$data = array(
'lat' => $request->lat,
'lng' => $request->lng,
'foto' => $request->foto
);
for($i=0;$i < count($usuariosAnjos); $i++){
Mail::send('email', $data, function ($message){
$message->from('[email protected]', 'teste!');
$message->to($usuariosAnjos[$i]);
});
}
return response()->json("Email enviado com sucesso", 201);
}
If I put a return response()->json($usuariosAnjos, 201);
I have a array
with two emails, I do not understand why it says that this variable is undefined.