Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param $username
  * @param MailRequest $request
  * @return Response
  */
 public function store($username, MailRequest $request)
 {
     $receiver = $this->user->findOrFailByUsername($username);
     $m = $request->user()->messages()->create(['message' => $request->message, 'reciever_id' => $receiver->id]);
     if ($m) {
         // Create notification and dispatch it
         $receiver->newNotification()->from($request->user())->withType('UserMessageSent')->withSubject('New message!')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has sent you " . link_to_route('messages.show', "new message", $request->user()->username))->regarding($m)->deliver();
         // Sends email to reciever if activated notifications
         if ($receiver->email_notifications_new_message == true) {
             $this->dispatch(new SendNewMessageEmail($m, $request->user(), $receiver));
         }
         return redirect()->route('messages.show', $receiver->username)->with('message', "Message Sent!");
     }
     return back()->with('error', "Error! Something not well.");
 }