/** * @param int $id * @param Request $request * @param MessageFormatter $formatter * * @return \Illuminate\View\View */ public function getRead($id, Request $request, MessageFormatter $formatter) { $conversation = $this->conversationRepository->find($id); if (!$conversation || !$conversation->participants->contains($this->guard->user())) { throw new ConversationNotFoundException(); } Breadcrumbs::setCurrentRoute('conversations.read', $conversation); $this->conversationRepository->updateLastRead($conversation, $this->guard->user()); // Load the participants here as we're changing them above and we want to avoid caching issues $conversation->load('participants'); $messages = $this->conversationMessageRepository->getAllForConversation($conversation); $preview = null; if ($request->has('message')) { $preview = new ConversationMessage(['author_id' => $this->guard->user()->id, 'message' => $request->get('message'), 'message_parsed' => $formatter->parse($request->get('message'), [MessageFormatter::ME_USERNAME => $this->guard->user()->name]), 'created_at' => new \DateTime()]); } return view('conversation.show', compact('conversation', 'messages', 'preview')); }