/** * Display a listing of the Comment. * GET|HEAD /comments * * @return Response */ public function index(Request $request) { $offset = $request->page ? $request->page : 1; $limit = $request->limit ? $request->limit : 12; $post_id = $request->post_id; $offset = ($offset - 1) * $limit; if ($post_id) { $posts = Comment::where('postId', $post_id)->orderBy('id', 'desc')->offset($offset)->limit($limit)->get(); foreach ($posts as $key => $value) { $posts[$key]['human_created_at'] = $value->created_at->diffForHumans(); $posts[$key]['human_updated_at'] = $value->updated_at->diffForHumans(); } } else { $posts = Comment::orderBy('id', 'desc')->offset($offset)->limit($limit)->get(); } return response()->json($posts); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $comments = Comment::orderBy('seen', 'asc')->orderBy('created_at', 'desc')->paginate($this->itemPerPage); return view('admin.comments.index', compact('comments')); }
/** * Handles the request to adminComments page * If the user is logged in - returns the view * Else redirects him to login page * @return type view | Redirect */ public function adminComments() { if (Auth::check()) { $data = ['title' => 'Comments', 'comments' => Comment::orderBy('created_at', 'DESC')->paginate(10)]; return view('pages.mainAdminPages.adminComments')->with($data); } else { return Redirect::route('admin'); } }