Merge branch 'issue-84' into 'develop'
fix: 🐛 add another condition to test if the user subscribe to the ticket in Message.php
See merge request ldc-web/projets/support-web!109
This commit is contained in:
commit
cc339201f0
4 changed files with 11 additions and 15 deletions
|
|
@ -338,15 +338,14 @@ class TicketController extends Controller
|
|||
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
|
||||
// Subscribe to ticket.
|
||||
if ($request->subscribe) {
|
||||
if (!$user->subscriptions()->find($ticket->id)) {
|
||||
$user->subscriptions()->attach($ticket->id);
|
||||
}
|
||||
} elseif ($user->subscriptions()->find($ticket->id)) {
|
||||
$user->subscriptions()->syncWithoutDetaching([$ticket->id]);
|
||||
} else {
|
||||
$user->subscriptions()->detach($ticket->id);
|
||||
}
|
||||
|
||||
// Store files if any.
|
||||
if (isset($filesMessage) and $filesMessage) {
|
||||
foreach ($filesMessage as $key => $singleFile) {
|
||||
if ($key === 0) {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ class CreateMessage extends FormRequest
|
|||
*/
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
$this->merge([
|
||||
'subscribe' => $this->subscribe ? true : false,
|
||||
'type' => $this->is_private ? MessageTypeEnum::private->value : MessageTypeEnum::public->value
|
||||
|
|
|
|||
|
|
@ -96,14 +96,9 @@ class Message extends Model
|
|||
}
|
||||
// ? Is message author is admin ?
|
||||
if ($messageUser->isAdmin()) {
|
||||
// Url: 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.'));
|
||||
}
|
||||
$messageUser->subscriptions()->syncWithoutDetaching([$ticket->id]);
|
||||
\session()->flash('info', trans('Vous avez été inscrit.'));
|
||||
}
|
||||
// * Send mail to other subscribed users
|
||||
event(new NotifySubscriptions(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@can('changeStatus', App\Model\Ticket::class)
|
||||
@can('changeStatus', App\Models\Ticket::class)
|
||||
<div class="form-group col">
|
||||
<label class="col-form-label" for="status">{{ __('Status') }}</label>
|
||||
<select class="form-select" id="status" name="status">
|
||||
|
|
@ -75,7 +75,7 @@
|
|||
<input name="status" type="hidden" value="{{ \App\Enums\Tickets\TicketStatusEnum::new }}" required>
|
||||
@endcan
|
||||
|
||||
@can('assignLabels', App\Model\Ticket::class)
|
||||
@can('assignLabels', App\Models\Ticket::class)
|
||||
<div class="form-group col">
|
||||
<label class="col-form-label" for="labels">{{ __('Étiquettes') }}</label>
|
||||
<div class="row">
|
||||
|
|
@ -127,7 +127,7 @@
|
|||
<hr>
|
||||
@endfor
|
||||
|
||||
@can('changeInternalStatus', App\Model\Ticket::class)
|
||||
@can('changeInternalStatus', App\Models\Ticket::class)
|
||||
<div class="form-group text-center">
|
||||
<input id="is_internal" name="is_internal" type="checkbox" @if (old('is_internal', isset($ticket) and $ticket->is_internal)) checked @endif>
|
||||
<label class="col-form-label" for="is_internal">Ticket interne</label>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue