create notification on delete task, assign user and unassign user
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Events\TaskParticipationCancelled;
|
||||
use App\Events\VolunteerAssignedToTask;
|
||||
use App\Events\VolunteerUnassignedFromTask;
|
||||
use App\Models\Events;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -88,6 +89,10 @@ class TasksController extends Controller
|
||||
|
||||
if($user) {
|
||||
$task->users()->attach($id);
|
||||
$notification = Notification::create([
|
||||
'content' => "Vous avez été assigné à la tâche {$task->title} de l'événement {$task->event->name}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
broadcast(new VolunteerAssignedToTask(
|
||||
$user->id,
|
||||
$task,
|
||||
@@ -131,6 +136,12 @@ class TasksController extends Controller
|
||||
}
|
||||
|
||||
$participants = $task->users;
|
||||
if ($participants->isNotEmpty()) {
|
||||
$notification = Notification::create([
|
||||
'content' => "La tâche '{$task->title}' pour l'événement '{$task->event->name}' a été supprimée. Vous n'y participez donc plus."
|
||||
]);
|
||||
$notification->users()->attach($participants->pluck('id'));
|
||||
}
|
||||
|
||||
foreach ($participants as $user) {
|
||||
broadcast(new TaskParticipationCancelled(
|
||||
@@ -227,7 +238,10 @@ class TasksController extends Controller
|
||||
|
||||
if ($user) {
|
||||
$task->users()->detach($id);
|
||||
|
||||
$notification = Notification::create([
|
||||
'content' => "Vous avez été désassigné de la tâche {$task->title} de l'événement {$task->event->name}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
broadcast(new VolunteerUnassignedFromTask(
|
||||
$user->id,
|
||||
$task,
|
||||
|
||||
Reference in New Issue
Block a user