-
app/Mail/AbsenceNotification.php
Open in GitHubuse App\Models\Enrollment; use App\Models\Event; use App\Models\Student; use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class AbsenceNotification extends Mailable { use Queueable; use SerializesModels; public $enrollment; public function __construct(public Event $event, public User $student) { $nstudent = Student::where('id', $student->id)->first(); $this->enrollment = Enrollment::where('student_id', $nstudent->id)->where('course_id', $event->course_id)->first(); } public function build() { return $this ->subject(__('Absence Notification')) ->view('emails.absence_notification'); } }
-
app/Jobs/WatchAttendance.php
Open in GitHubuse App\Mail\AbsenceNotification; use App\Models\Attendance; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Mail; class WatchAttendance implements ShouldQueue { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; public $tries = 5; public function __construct(protected Attendance $attendance) { } public function handle() { if ($this->attendance->attendance_type_id == 4) { $student = $this->attendance->student; $otherRecipients = []; if ($this->attendance->event->teacher->email !== null) { array_push($otherRecipients, ['email' => $this->attendance->event->teacher->email]); } if (config('settings.manager_email') !== null) { array_push($otherRecipients, ['email' => explode(',', config('settings.manager_email'))]); } foreach ($this->attendance->student->contacts as $contact) { array_push($otherRecipients, ['email' => $contact->email]); } Mail::to($student->user->email) ->locale($student->user->locale) ->cc($otherRecipients) ->queue(new AbsenceNotification($this->attendance->event, $student->user)); } } }