/**
  * [Handle the command]
  * @param  [type] $command [description]
  * @return [type]          [description]
  */
 public function handle($command)
 {
     $message1 = Message::publish($command->user_id, $command->message, $command->global);
     $this->messageRepository->save($message1);
     $this->dispatchEventsFor($message1);
     return $message1;
 }
Пример #2
0
function createThreads()
{
    $thread = Thread::create(['subject' => "Check"]);
    // Message
    Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => "Hellooooo."]);
    // Sender
    Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]);
    // Recipients
}
Пример #3
0
 public function save(Message $message)
 {
     return $message->save();
 }
Пример #4
0
 /**
  * Adds a new message to a current thread
  *
  * @param $id
  * @return mixed
  */
 public function update($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return Redirect::to('messages');
     }
     $thread->activateAllParticipants();
     // Message
     Message::create(['thread_id' => $thread->id, 'user_id' => Auth::id(), 'body' => Input::get('message')]);
     // Add replier as a participant
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants(Input::get('recipients'));
     }
     return Redirect::to('messages/' . $id);
 }