/**
  * 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;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $messageIds = DB::table('messages')->lists('id');
     $messageSenderIds = DB::table('messages')->lists('senderid');
     foreach ($messageIds as $messageId) {
         MessageResponse::create(['body' => $faker->sentence, 'message_id' => $messageId, 'senderid' => $faker->randomElement($messageSenderIds), 'receiverid' => 1, 'sendername' => $faker->name, 'senderprofileimage' => $faker->imageUrl($width = 180, $height = 180)]);
     }
 }
 /**
  * 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);
     }
 }