create notification on delete task, assign user and unassign user
This commit is contained in:
1 parent
9986dfa956
commit
d51d6a9c3f
1 file changed
+15
-1
@@ -6,6 +6,7 @@ use App\Events\TaskParticipationCancelled;
|
|||||||
use App\Events\VolunteerAssignedToTask;
|
use App\Events\VolunteerAssignedToTask;
|
||||||
use App\Events\VolunteerUnassignedFromTask;
|
use App\Events\VolunteerUnassignedFromTask;
|
||||||
use App\Models\Events;
|
use App\Models\Events;
|
||||||
|
use App\Models\Notification;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@@ -88,6 +89,10 @@ class TasksController extends Controller
|
|||||||
|
|
||||||
if($user) {
|
if($user) {
|
||||||
$task->users()->attach($id);
|
$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(
|
broadcast(new VolunteerAssignedToTask(
|
||||||
$user->id,
|
$user->id,
|
||||||
$task,
|
$task,
|
||||||
@@ -131,6 +136,12 @@ class TasksController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$participants = $task->users;
|
$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) {
|
foreach ($participants as $user) {
|
||||||
broadcast(new TaskParticipationCancelled(
|
broadcast(new TaskParticipationCancelled(
|
||||||
@@ -227,7 +238,10 @@ class TasksController extends Controller
|
|||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$task->users()->detach($id);
|
$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(
|
broadcast(new VolunteerUnassignedFromTask(
|
||||||
$user->id,
|
$user->id,
|
||||||
$task,
|
$task,
|
||||||
|
|||||||
Reference in new issue
Block a user