remove Mail use from Notifications classes
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\EventParticipationCancelledMail;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Models\Task;
|
||||
use App\Notifications\EventDeleted;
|
||||
@@ -94,6 +96,18 @@ class EventsController extends Controller
|
||||
|
||||
if ($participants->isNotEmpty()) {
|
||||
Notification::send($participants, new EventDeleted($event));
|
||||
|
||||
foreach ($participants as $user) {
|
||||
if ($user->email_notifications) {
|
||||
Mail::to($user->email)->send(new EventParticipationCancelledMail([
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'eventName' => $event->name,
|
||||
'start' => $event->start,
|
||||
'end' => $event->end,
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\TaskDateUpdateMail;
|
||||
use App\Mail\TaskParticipationCancelledMail;
|
||||
use App\Mail\VolunteerAssignToTaskMail;
|
||||
use App\Mail\VolunteerUnassignToTaskMail;
|
||||
use App\Notifications\TaskDateUpdated;
|
||||
use App\Notifications\TaskDeleted;
|
||||
use App\Notifications\VolunteerAssignedToTask;
|
||||
use App\Notifications\VolunteerUnassignedFromTask;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
@@ -91,8 +96,19 @@ class TasksController extends Controller
|
||||
$task->users()->attach($id);
|
||||
|
||||
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||
$event = Event::findOrFail($task->events_id);
|
||||
$user->notify(new VolunteerAssignedToTask($task, $event));
|
||||
}
|
||||
|
||||
if ($user->email_notifications) {
|
||||
Mail::to($user->email)->send(new VolunteerAssignToTaskMail([
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $task->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
]));
|
||||
} }
|
||||
|
||||
return response()->json(['message' => 'Task assigned'], 200);
|
||||
|
||||
@@ -128,6 +144,19 @@ class TasksController extends Controller
|
||||
|
||||
if (Carbon::now()->lessThanOrEqualTo($task->end) && $task->users->isNotEmpty()) {
|
||||
Notification::send($task->users, new TaskDeleted($task, $event));
|
||||
|
||||
foreach ($task->users as $user) {
|
||||
if ($user->email_notifications) {
|
||||
Mail::to($user->email)->send(new TaskParticipationCancelledMail([
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $event->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$task->delete();
|
||||
@@ -162,6 +191,21 @@ class TasksController extends Controller
|
||||
newStart: FormatDate::formatDate($request['start']),
|
||||
newEnd: FormatDate::formatDate($request['end']),
|
||||
));
|
||||
|
||||
foreach ($task->users as $user) {
|
||||
if ($user->email_notifications) {
|
||||
Mail::to($user->email)->send(new TaskDateUpdateMail([
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'oldStart' => FormatDate::formatDate($task->start),
|
||||
'oldEnd' => FormatDate::formatDate($task->end),
|
||||
'newStart' => $request['start'],
|
||||
'newEnd' => $request['end'],
|
||||
'eventName' => $event->name,
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$task->update([
|
||||
@@ -219,6 +263,17 @@ class TasksController extends Controller
|
||||
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||
$event = Event::findOrFail($task->events_id);
|
||||
$user->notify(new VolunteerUnassignedFromTask($task, $event));
|
||||
|
||||
if ($user->email_notifications) {
|
||||
Mail::to($user->email)->send(new VolunteerUnassignToTaskMail([
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $task->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User unassigned successfully'], 200);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\RegisterMail;
|
||||
use App\Mail\UpdateRoleMail;
|
||||
use App\Notifications\VolunteerRoleUpdated;
|
||||
use App\Mail\CreateUserByAdminMail;
|
||||
use App\Mail\DeactivateAccountMail;
|
||||
@@ -56,6 +58,17 @@ class UserController extends Controller
|
||||
$admins = User::whereIn('role', [1, 2])->get();
|
||||
Notification::sendNow($admins, new UserRegistered($user));
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
if ($admin->email_notifications) {
|
||||
Mail::to($admin->email)->send(new RegisterMail([
|
||||
'adminName' => $admin->name,
|
||||
'adminLastname' => $admin->lastname,
|
||||
'userName' => $user->name,
|
||||
'userLastname' => $user->lastname,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User created successfully']);
|
||||
}
|
||||
|
||||
@@ -244,6 +257,14 @@ class UserController extends Controller
|
||||
|
||||
$user->notify(new VolunteerRoleUpdated($role));
|
||||
|
||||
if ($user->email_notifications) {
|
||||
Mail::to($user->email)->send(new UpdateRoleMail([
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'role' => $role,
|
||||
]));
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User role added successfully']);
|
||||
} catch(\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user