Blame view
app/Observers/MessageObserver.php
1.88 KB
09a2fc9d8 messages and subs... |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
<?php namespace App\Observers; use App\Mail\SendMessage; use App\Mail\SendVacancyMessage; use App\Models\Ad_employer; use App\Models\Message; use App\Models\User; use Illuminate\Support\Facades\Mail; class MessageObserver { /** * Handle the Message "created" event. * * @param \App\Models\Message $message * @return void */ public function created(Message $message) { $toUserId = $message->to_user_id; $fromUserId = $message->user_id; $toUser =User::query()->where('id',$toUserId)->first(); $fromUser =User::query()->where('id',$fromUserId)->first(); if ($toUser && !empty($toUser->subscribe_email) && $toUser->subscribe==1 ){ if ( (int) $message->ad_employer_id === 0 ){ Mail::to($toUser->subscribe_email)->send(new SendMessage($message,$fromUser)); }else{ $vacancy=Ad_employer::find($message->ad_employer_id); Mail::to($toUser->subscribe_email)->send(new SendVacancyMessage($message,$fromUser,$vacancy)); } } } /** * Handle the Message "updated" event. * * @param \App\Models\Message $message * @return void */ public function updated(Message $message) { // } /** * Handle the Message "deleted" event. * * @param \App\Models\Message $message * @return void */ public function deleted(Message $message) { // } /** * Handle the Message "restored" event. * * @param \App\Models\Message $message * @return void */ public function restored(Message $message) { // } /** * Handle the Message "force deleted" event. * * @param \App\Models\Message $message * @return void */ public function forceDeleted(Message $message) { // } } |