Пример #1
0
 /**
  * Execute the command.
  *
  * @param UserRepository $userRepository
  *
  * @param ResponseRepository $responseRepository
  *
  * @return void
  */
 public function handle(UserRepository $userRepository, MessageRepository $messageRepository)
 {
     $message = Message::createMessage($this->body, $this->senderId, $this->senderProfileImage, $this->senderName);
     $response = MessageResponse::createMessageResponse($this->body, $this->senderId, $this->receiverId, $this->senderProfileImage, $this->senderName);
     $userRepository->findById($this->receiverId)->messages()->save($message);
     $messageRepository->findById($message->id)->messageResponses()->save($response);
     $userRepository->findById($this->receiverId)->messageResponses()->save($response);
     return true;
 }
 /**
  * Execute the command.
  *
  * @param UserRepository, $userRepository
  *
  * @param EmailRepository $emailRepository
  *
  * @return void
  */
 public function handle(UserRepository $userRepository, MessageRepository $messageRepository)
 {
     $user = $userRepository->findById($this->receiverId);
     $message = $messageRepository->findById($this->messageId);
     if (!$message->belongsToUser($this->receiverId)) {
         $user->messages()->save($message);
     }
     if ($this->receiverId == $this->senderId) {
         $userIdToSaveTo = $message->getLastReceiverId();
         $messageResponse = MessageResponse::createMessageResponse($this->body, $this->senderId, $userIdToSaveTo, $this->senderProfileImage, $this->senderName);
         $messageRepository->findById($this->messageId)->messageResponses()->save($messageResponse);
         $userRepository->findById($userIdToSaveTo)->messageResponses()->save($messageResponse);
     } else {
         $messageResponse = MessageResponse::createMessageResponse($this->body, $this->senderId, $this->receiverId, $this->senderProfileImage, $this->senderName);
         $messageRepository->findById($this->messageId)->messageResponses()->save($messageResponse);
         $user->messageResponses()->save($messageResponse);
     }
 }
Пример #3
0
 /**
  * Display the specified message.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function show($id, MessageRepository $messageRepository)
 {
     $user = $this->currentUser;
     $message = $messageRepository->findByIdWithMessageResponses($id);
     return view('messages.show', compact('user', 'message'));
 }