-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNotifyCompanyRoles.php
51 lines (44 loc) · 1.26 KB
/
NotifyCompanyRoles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace App\Jobs;
use App\Models\Company;
use App\Models\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
class NotifyCompanyRoles implements ShouldQueue
{
use Queueable;
/**
* Create a new job instance.
*/
public function __construct(
public string $receiver,
public Company $company,
public string $emailTemplate,
) {
}
/**
* Execute the job.
*/
public function handle(): void
{
if (!$this->company->is_approved) {
return;
}
$users = collect();
if ($this->receiver == 'crew') {
$users = User::role(['event organizer', 'assistant organizer'])->get();
} else if ($this->receiver == 'company representative') {
if ($representative = $this->company->representative) {
$users->push($representative);
}
}
// Send emails to the users
foreach ($users as $user) {
Mail::to($user->email)->send(new $this->emailTemplate($user, $this->company));
}
}
}