예제 #1
0
 /**
  * Stores a new message thread
  *
  * @return mixed
  */
 public function store()
 {
     $input = Input::all();
     $thread = Thread::create(['subject' => $input['subject']]);
     // Message
     Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]);
     // Sender
     Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]);
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants($input['recipients']);
     }
     return redirect('messages');
 }
예제 #2
0
 public function createRoom()
 {
     $input = Input::all();
     $thread = Thread::create(['subject' => $input['subject']]);
     // Message
     $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]);
     // Sender
     Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]);
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants($input['recipients']);
     }
     $data = array('room' => $thread->id, 'message' => array('body' => Str::words($message->body, 60), 'user_id' => Auth::user()->id));
     event(new ChatRoomCreated($data));
     return redirect(App::getLocale() . '/chat');
 }