remove Mail use from Notifications classes
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Mail\EventParticipationCancelledMail;
|
||||||
use App\Models\Event;
|
use App\Models\Event;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
use App\Notifications\EventDeleted;
|
use App\Notifications\EventDeleted;
|
||||||
@@ -94,6 +96,18 @@ class EventsController extends Controller
|
|||||||
|
|
||||||
if ($participants->isNotEmpty()) {
|
if ($participants->isNotEmpty()) {
|
||||||
Notification::send($participants, new EventDeleted($event));
|
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;
|
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\TaskDateUpdated;
|
||||||
use App\Notifications\TaskDeleted;
|
use App\Notifications\TaskDeleted;
|
||||||
use App\Notifications\VolunteerAssignedToTask;
|
use App\Notifications\VolunteerAssignedToTask;
|
||||||
use App\Notifications\VolunteerUnassignedFromTask;
|
use App\Notifications\VolunteerUnassignedFromTask;
|
||||||
use App\Models\Event;
|
use App\Models\Event;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -91,8 +96,19 @@ class TasksController extends Controller
|
|||||||
$task->users()->attach($id);
|
$task->users()->attach($id);
|
||||||
|
|
||||||
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||||
|
$event = Event::findOrFail($task->events_id);
|
||||||
$user->notify(new VolunteerAssignedToTask($task, $event));
|
$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);
|
return response()->json(['message' => 'Task assigned'], 200);
|
||||||
|
|
||||||
@@ -128,6 +144,19 @@ class TasksController extends Controller
|
|||||||
|
|
||||||
if (Carbon::now()->lessThanOrEqualTo($task->end) && $task->users->isNotEmpty()) {
|
if (Carbon::now()->lessThanOrEqualTo($task->end) && $task->users->isNotEmpty()) {
|
||||||
Notification::send($task->users, new TaskDeleted($task, $event));
|
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();
|
$task->delete();
|
||||||
@@ -162,6 +191,21 @@ class TasksController extends Controller
|
|||||||
newStart: FormatDate::formatDate($request['start']),
|
newStart: FormatDate::formatDate($request['start']),
|
||||||
newEnd: FormatDate::formatDate($request['end']),
|
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([
|
$task->update([
|
||||||
@@ -219,6 +263,17 @@ class TasksController extends Controller
|
|||||||
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||||
$event = Event::findOrFail($task->events_id);
|
$event = Event::findOrFail($task->events_id);
|
||||||
$user->notify(new VolunteerUnassignedFromTask($task, $event));
|
$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);
|
return response()->json(['message' => 'User unassigned successfully'], 200);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Mail\RegisterMail;
|
||||||
|
use App\Mail\UpdateRoleMail;
|
||||||
use App\Notifications\VolunteerRoleUpdated;
|
use App\Notifications\VolunteerRoleUpdated;
|
||||||
use App\Mail\CreateUserByAdminMail;
|
use App\Mail\CreateUserByAdminMail;
|
||||||
use App\Mail\DeactivateAccountMail;
|
use App\Mail\DeactivateAccountMail;
|
||||||
@@ -56,6 +58,17 @@ class UserController extends Controller
|
|||||||
$admins = User::whereIn('role', [1, 2])->get();
|
$admins = User::whereIn('role', [1, 2])->get();
|
||||||
Notification::sendNow($admins, new UserRegistered($user));
|
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']);
|
return response()->json(['message' => 'User created successfully']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +257,14 @@ class UserController extends Controller
|
|||||||
|
|
||||||
$user->notify(new VolunteerRoleUpdated($role));
|
$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']);
|
return response()->json(['message' => 'User role added successfully']);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
Log::info($e->getMessage());
|
Log::info($e->getMessage());
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ class EventDeleted extends Notification implements ShouldBroadcast
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,15 +40,4 @@ class EventDeleted extends Notification implements ShouldBroadcast
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): void
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new EventParticipationCancelledMail([
|
|
||||||
'name' => $notifiable->name,
|
|
||||||
'lastname' => $notifiable->lastname,
|
|
||||||
'eventName' => $this->event->name,
|
|
||||||
'start' => $this->event->start,
|
|
||||||
'end' => $this->event->end,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,6 @@ class TaskDateUpdated extends Notification implements ShouldBroadcast
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,18 +53,4 @@ class TaskDateUpdated extends Notification implements ShouldBroadcast
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): void
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new TaskDateUpdateMail([
|
|
||||||
'name' => $notifiable->name,
|
|
||||||
'lastname' => $notifiable->lastname,
|
|
||||||
'taskName' => $this->task->name,
|
|
||||||
'oldStart' => $this->oldStart,
|
|
||||||
'oldEnd' => $this->oldEnd,
|
|
||||||
'newStart' => $this->newStart,
|
|
||||||
'newEnd' => $this->newEnd,
|
|
||||||
'eventName' => $this->event->name,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ class TaskDeleted extends Notification implements ShouldBroadcast
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,16 +45,4 @@ class TaskDeleted extends Notification implements ShouldBroadcast
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): void
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new TaskParticipationCancelledMail([
|
|
||||||
'name' => $notifiable->name,
|
|
||||||
'lastname' => $notifiable->lastname,
|
|
||||||
'taskName' => $this->task->name,
|
|
||||||
'start' => $this->event->start,
|
|
||||||
'end' => $this->task->end,
|
|
||||||
'eventName' => $this->event->name,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ class UserRegistered extends Notification implements ShouldBroadcast
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,16 +41,4 @@ class UserRegistered extends Notification implements ShouldBroadcast
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): MailMessage
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new RegisterMail([
|
|
||||||
'adminName' => $notifiable->name,
|
|
||||||
'adminLastname'=> $notifiable->lastname,
|
|
||||||
'userName' => $this->user->name,
|
|
||||||
'userLastname' => $this->user->lastname,
|
|
||||||
]));
|
|
||||||
|
|
||||||
return (new MailMessage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ class VolunteerAssignedToTask extends Notification implements ShouldBroadcast
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,16 +45,4 @@ class VolunteerAssignedToTask extends Notification implements ShouldBroadcast
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): void
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new VolunteerAssignToTaskMail([
|
|
||||||
'name' => $notifiable->name,
|
|
||||||
'lastname' => $notifiable->lastname,
|
|
||||||
'taskName' => $this->task->name,
|
|
||||||
'start' => $this->task->start,
|
|
||||||
'end' => $this->task->end,
|
|
||||||
'eventName' => $this->event->name,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ class VolunteerRoleUpdated extends Notification implements ShouldBroadcast
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +39,4 @@ class VolunteerRoleUpdated extends Notification implements ShouldBroadcast
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): void
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new UpdateRoleMail([
|
|
||||||
'name' => $notifiable->name,
|
|
||||||
'lastname' => $notifiable->lastname,
|
|
||||||
'role' => $this->role,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ class VolunteerUnassignedFromTask extends Notification implements ShouldBroadcas
|
|||||||
$channels[] = 'broadcast';
|
$channels[] = 'broadcast';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notifiable->email_notifications) {
|
|
||||||
$channels[] = 'mail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $channels;
|
return $channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,16 +45,4 @@ class VolunteerUnassignedFromTask extends Notification implements ShouldBroadcas
|
|||||||
{
|
{
|
||||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toMail($notifiable): void
|
|
||||||
{
|
|
||||||
Mail::to($notifiable->email)->send(new VolunteerUnassignToTaskMail([
|
|
||||||
'name' => $notifiable->name,
|
|
||||||
'lastname' => $notifiable->lastname,
|
|
||||||
'taskName' => $this->task->name,
|
|
||||||
'start' => $this->task->start,
|
|
||||||
'end' => $this->task->end,
|
|
||||||
'eventName' => $this->event->name,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user