/**
  * {@inheritdoc}
  */
 public function create(array $details)
 {
     $conversation = null;
     $this->dbManager->transaction(function () use($details, &$conversation) {
         $conversation = $this->conversationModel->create(['title' => $details['title']]);
         $this->conversationMessageRepository->addMessageToConversation($conversation, ['author_id' => $this->guard->user()->id, 'message' => $details['message']], false);
         // First add the author of this message - if he answered it he also read the conversation
         $conversation->participants()->attach($this->guard->user()->id, ['last_read' => new \DateTime()]);
         // And now add all other participants
         $this->addParticipants($conversation, $details['participants']);
     });
     return $conversation;
 }
 /**
  * @param int          $id
  * @param ReplyRequest $request
  * @param Store        $settings
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postReply($id, ReplyRequest $request, Store $settings)
 {
     $this->failedValidationRedirect = route('conversations.read', ['id' => $id]);
     /** @var Conversation $conversation */
     $conversation = $this->conversationRepository->find($id);
     if (!$conversation || !$conversation->participants->contains($this->guard->user())) {
         throw new ConversationNotFoundException();
     }
     $message = $this->conversationMessageRepository->addMessageToConversation($conversation, ['author_id' => $this->guard->user()->id, 'message' => $request->input('message')]);
     if ($message) {
         $page = 1;
         if ($settings->get('conversations.message_order', 'desc') == 'asc') {
             $page = (int) ($conversation->messages->count() / $settings->get('user.posts_per_page', 10)) + 1;
         }
         return redirect()->route('conversations.read', ['id' => $conversation->id, 'page' => $page]);
     }
     return redirect()->route('conversations.read', ['id' => $conversation->id])->withInput()->withErrors(['content' => 'Error']);
 }