/** * GET /posts * Get a listing of all posts. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function index(Request $request) { $posts = Post::with('tags', 'series')->published()->latest()->paginate(10); $page = $request->get('page'); $title = $page ? "All posts (Page {$page})" : 'All posts'; return view('posts.index', compact('posts'))->withTitle($title); }
/** * GET / * The home page. * * @return \Illuminate\Http\Response */ public function index() { $latestPosts = Post::with('tags')->published()->latest()->take(5)->get(); $popularPosts = Post::published()->with('tags')->whereNotIn('id', $latestPosts->modelKeys())->orderBy('views', 'desc')->take(5)->get(); return view('pages.index', compact('latestPosts', 'popularPosts'))->withTitle('A blog on Laravel & Rails'); }
/** * GET /admin/posts * Display all of the posts. * * @return \Illuminate\View\View */ public function index() { $posts = Post::with('user')->latest()->paginate(25); return view('admin.posts.index', compact('posts'))->withTitle('All posts'); }