Ejemplo n.º 1
0
 public function store()
 {
     $message = new Message(Input::all());
     $message->creator_id = user()->id;
     $message->updater_id = user()->id;
     $message->createSlug();
     $message->setReceiverByName(Input::get('receiver_name'));
     $okay = $message->save();
     if ($okay) {
         // Reset the message counter cache of the receiving user:
         Cache::forget(User::CACHE_KEY_MESSAGES . $message->receiver_id);
         $this->alertFlash(trans('messages::message_sent'));
         return Redirect::to('messages/outbox');
     } else {
         return Redirect::to('messages/create')->withInput()->withErrors($message->getErrors());
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new message that addresses this user
  * 
  * @param  string   $title        The message title
  * @param  string   $text         The message text
  * @param  int      $creatorId    The user ID of the creator
  * @param  boolean  $sentBySystem [description]
  * @return void
  */
 public function sendMessage($title, $text, $creatorId = null, $sentBySystem = false)
 {
     if (!$creatorId) {
         if (user()) {
             $creatorId = user()->id;
         } else {
             $creatorId = 1;
             // Daemon
             $sentBySystem = true;
         }
     }
     $message = new Message(['title' => $title, 'text' => $text]);
     $message->creator_id = $creatorId;
     $message->updater_id = $creatorId;
     $message->receiver_id = $this->id;
     $message->sent_by_system = true;
     $message->createSlug();
     $message->save();
 }