inboxAction->execute($recipient, $sender); // update the inbox with the last message and last user as current user $inbox->last_message = $data['message']; $inbox->last_user_id = $sender->id; $inbox->save(); // create a new message in the inbox $message = $inbox->messages()->create([ 'message' => $data['message'], 'user_id' => $sender->id, ]); // Send the message to all other users in the inbox broadcast(new MessageSent($message))->toOthers(); DB::commit(); } catch (\Throwable $e) { DB::rollBack(); throw new MessageNotSendException('Message not sent.', previous: $e); } } }