예제 #1
0
 /**
  * Shows a message thread
  *
  * @param $id
  * @return mixed
  */
 public function show($id)
 {
     try {
         if (Auth::user()) {
             $user = Auth::user();
             $thread = Thread::findOrFail($id);
             $threads = Thread::forUser($user->id)->latest('updated_at')->get();
         } else {
             return redirect()->to('auth/login');
         }
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect(App::getLocale() . '/messages');
     }
     // show current user in list if not a current participant
     //         $users = User::whereNotIn('id', $thread->participantsUserIds())->get();
     // don't show the current user in list
     $userId = Auth::user()->id;
     $participants_list = User::whereNotIn('id', $thread->participantsUserIds($userId))->get();
     $users = User::all();
     $thread->markAsRead($userId);
     event(new UserEnteredChatEvent($user));
     return view('messages.show', compact('thread', 'threads', 'participants_list', 'users', 'user', 'userId'));
 }