warpig's avatar
Level 12

blank page localhost

I'm trying to make a get request to show the homepage on localhost but in return I'm only seeing a blank page

Route::get('/', [PostController::class, 'home'])->name('home');

i am trying to return my view: "blog". When I inspect the page source in firefox, the correct page with my code loads correctly but it is not showing the frontend. I've cleared the cache, route, ran php artisan optimize:clear but everything stays the same. What am i missing?

It has been a while since I worked on the site, so i updated Docker and composer packages. The network tab shows this and i am currently trying to figure out how to solve it but in case anyone has encountered this issue I would like to know your thoughts. Thanks.

The resource at “<URL>” was blocked because content blocking is enabled.
<script> source URI is not allowed in this document: “https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5338710529457277”.
Module source URI is not allowed in this document: “http://localhost:5173/@vite/client”.
Module source URI is not allowed in this document: “http://localhost:5173/resources/js/app.js”.
Some cookies are misusing the recommended “SameSite“ attribute 4 

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5338710529457277. (Reason: CORS request did not succeed). Status code: (null).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5173/@vite/client. (Reason: CORS request did not succeed). Status code: (null).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5173/resources/js/app.js. (Reason: CORS request did not succeed). Status code: (null).

I've disabled all ad-blockers since

0 likes
1 reply
warpig's avatar
Level 12

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'
        ));
    }

Please or to participate in this conversation.