I got everything working in terms of sending emails and templating. Now I want to replace the static to: email@test.com
with users' email with specific roles.
I have this code written:
public function envelope()
{
return new Envelope(
from: 'amushref@hsse.co',
to: [
User::with("roles")->whereHas("roles", function($q) {
$q->whereIn("id", [
1, // Super Admin
6, // Admin
2, // Security Supervisor
5, // Security Manager
]);
})->get('email')
],
subject: 'New Incident: ' . str_pad($this->record->ir_number, 4, '0', STR_PAD_LEFT) .
' - ' .
$this->record->caseTypeRelationship->name .
' - ' . $this->record->locationRelationship->name,
);
}
I've made to:
as an array to include emails of the provided roles (id
). I get an error saying that the address are not correct/doesn't exist. What is the proper way to fetch emails of users of the selected roles?