From be43700f65990901fefed21f616564e44f51aa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 2 Feb 2022 16:47:47 +0100 Subject: [PATCH] Fix ticket answer when Admin to force subscribe --- app/Models/Message.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Models/Message.php b/app/Models/Message.php index 93467ce..4d533e6 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -41,8 +41,16 @@ class Message extends Model } // ? Is message author is admin ? if ($messageUser->isAdmin()) { - $ticket->subscriptions()->attach($messageUser); - \session()->flash('info', trans('Vous avez été inscrit.')); + // TODO: investigate why this make errors on prod, + // https://supportweb.ldc.fr/ticket/583/message/create + // SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '583-8' for key 'PRIMARY' + // $ticket->subscriptions()->attach($messageUser); + + // Add subscription + if (!$messageUser->subscriptions()->find($ticket->id)) { + $messageUser->subscriptions()->attach($ticket->id); + \session()->flash('info', trans('Vous avez été inscrit.')); + } } // * Send mail to other subscribed users event(new NotifySubscriptions(