/**
  * Display a listing of conversations.
  *
  * @return Response
  */
 public function index()
 {
     $favorites = Favorites::where('owner_id', \Auth::id())->with('user')->orderBy('updated_at', 'DES')->take(10)->get();
     //$user
     $conversations = User::where('id', \Auth::id())->with(['conversations' => function ($query) {
         $query->with(['lastMessage', 'otherUser', 'notReadCount'])->orderBy('created_at', 'DES');
     }])->first()->conversations;
     //Get current page form url e.g. &page=6
     $currentPage = (int) LengthAwarePaginator::resolveCurrentPage();
     if (!$currentPage) {
         $currentPage = 1;
     }
     $currentPage--;
     //Define how many items we want to be visible in each page
     $perPage = 20;
     //Slice the collection to get the items to display in current page
     $currentPageConversations = $conversations->slice($currentPage * $perPage, $perPage)->all();
     $conversations = new LengthAwarePaginator($currentPageConversations, count($conversations), $perPage);
     $conversations->setPath('/message');
     return view('messages', compact('conversations', 'favorites'));
 }
 /**
  * It deletes a favorite relation for a given user.
  *
  * @param  int  $id
  * @return Response
  */
 public function deleteFavorite($id)
 {
     if (\Auth::id() != $id) {
         if ($fav = Favorites::where('owner_id', '=', \Auth::id())->where('user_id', '=', $id)->first()) {
             $fav->delete();
         }
     }
     return redirect()->route('profile', $id);
 }