I'm currently using laravel 8 , i want to make sending email with condition but the $users is not undefined here's the code
public function email_officer(Complaint $complaint, Request $request){
if($complaint->destination_id == 1){$users = User::where('level', 'network')->get();}
elseif($complaint->destination_id == 2){$users = User::where('level', 'server')->get();}
elseif($complaint->destination_id == 3){$users = User::where('level', 'lms')->get();}
// Message to email
$data = [
'content' => 'incoming complaint ,
'url' => 'http://127.0.0.1:8000/login',
];
// Loop
foreach($users as $user){
Mail::to($user->email)->send(new SendMailOfficer($data));
}
return back()->with('toast_success','Sending Email Succesfully.');
}
before i use condition this code is working properly here's my previous code
public function email_officer(Complaint $complaint, Request $request){
$users = User::where('level', 'network')->get();
// Message to email
$data = [
'content' => 'incoming complaint ,
'url' => 'http://127.0.0.1:8000/login',
];
// Loop
foreach($users as $user){
Mail::to($user->email)->send(new SendMailOfficer($data));
}
return back()->with('toast_success','Sending Email Succesfully.');
}
can anyone help me to solve this as soon as posible thank you in advanced