The controller looks okay from a practical stance but I'm including just in case you might see something that might be of cause for this "blankpage"
public function home()
{
//show the latest post created
$latestPosts = Post::where('active', '=', 1)
->where('published_at', '<', Carbon::now())
->orderBy('published_at', 'desc')
->limit(3)
->get();
// show the 8 latest posts with more upvotes
$popularPosts = Post::query()
->whereNotIn('posts.id', $latestPosts->pluck('id'))
->leftJoin('upvote_downvotes', 'post_id', '=', 'upvote_downvotes.post_id')
->select('posts.*', DB::raw('COUNT(upvote_downvotes.id) as upvote_count'))
->where(function($query) {
$query->whereNull('upvote_downvotes.is_upvote')
->orWhere('upvote_downvotes.is_upvote', '=', 1);
})
->where('active', '=', 1)
->where('published_at', '<', Carbon::now())
->orderBy('created_at', 'desc')
->groupBy('posts.id')
->limit(8)
->get();
// show recent categories with latest posts
$categories = Category::query()
->whereNotIn('posts.id', $latestPosts->pluck('id'))
->whereHas('posts', function($query) {
$query->where('active', '=', 1)
->where('published_at', '<', Carbon::now());
})
->select('categories.*')
->selectRaw('MAX(posts.published_at) as max_date')
->leftJoin('category_post', 'categories.id', '=', 'category_post.category_id')
->leftJoin('posts', 'posts.id', '=', 'category_post.post_id')
->orderByDesc('max_date')
->groupBy('categories.id')
->limit(5)
->get();
// if authorized show recommended posts based on user upvotes
$user = auth()->user();
if ($user) {
$leftJoin = "(SELECT cp.category_id, cp.post_id FROM upvote_downvotes
JOIN category_post cp ON upvote_downvotes.post_id = cp.post_id
WHERE upvote_downvotes.is_upvote = 1 and upvote_downvotes.user_id = ?) as t";
$recommendedPosts = Post::query()
->leftJoin('category_post as cp', 'posts.id', '=', 'cp.post_id')
->leftJoin(DB::raw($leftJoin), function ($join) {
$join->on('t.category_id', '=', 'cp.category_id')
->on('t.post_id', '!=', 'cp.post_id');
})
->select('posts.*')
->where('posts.id', '!=', DB::raw('t.post_id'))
->setBindings([$user->id])
->limit(3)
->get();
// not authorized = popular posts based on views
} else {
$startWeek = Carbon::now()->subWeek()->startOfWeek();
$endWeek = Carbon::now()->subWeek()->endOfWeek();
$recommendedPosts = Post::query()
->leftJoin('post_views', 'posts.id', '=', 'post_views.post_id')
->select('posts.*', DB::raw('COUNT(post_views.id) as view_count'))
->where('active', '=', 1)
->withCount('views')->having('views_count', '>', 15)
->whereBetween('published_at',[$startWeek, $endWeek])
->groupBy('posts.id')
->limit(3)
->get();
}
return view('blog', compact(
'latestPosts',
'popularPosts',
'recommendedPosts',
'categories'
));
}