public function dashboard() { $totalVisitors = LaravelAnalyticsFacade::getVisitorsAndPageViews(30)->reduce(function ($carry, $day) { return $day['visitors'] + $carry; }, 0); $categories = PostCategory::with(['posts' => function ($query) { $query->where('published', 1); }])->get(); return view('admin.pages.dashboard')->with(compact('categories', 'totalVisitors')); }
public function showBlog($categorySlug = null) { if ($categorySlug) { $category = PostCategory::findBySlug($categorySlug); $posts = $category->posts()->where('published', 1)->orderBy('published_at', 'desc')->simplePaginate(10); $filters = PostCategory::with(['posts' => function ($query) { $query->where('published', 1); }])->where('slug', '<>', $categorySlug)->get(); } else { $category = $this->makeDefaultCategory(); $posts = Post::where('published', 1)->orderBy('published_at', 'desc')->simplePaginate(10); $filters = PostCategory::with(['posts' => function ($query) { $query->where('published', 1); }])->get(); } return view('front.blog.index')->with(compact('category', 'posts', 'filters')); }