Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

drannagg's avatar

Request is null on localhost request

Hi,

I am trying to gather data from my API with NextJS getServerSideProps but the request I receive in the controller is null. So I cannot access the parameters I need.

Could someone help me on this please? Here is the route:

Route::get('/test', [TestController::class, 'test']);

Here is the controller:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestController extends Controller
{
    public function test(Request $request) {
        return ($request);
    }
}

Thanks in advance.

0 likes
8 replies
drannagg's avatar

It is hitting http://localhost:8000/test.

The route is functional because it can return a string. But, the $request stay empty and $request->all() returns an empty array

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@drannagg Yes. You dont pass any request params so it returns nothing.. As expected

1 like
drannagg's avatar

@Sinnbeck

You are right! :) I added a query parameter and the the $request is not empty anymore. But I really do not understand why I cannot have the $request properties as if the request was made from a browser! :/

Sinnbeck's avatar

@drannagg I dont understand what you mean? What request parameters? Did you perhaps intend to use a POST request? In that case, it also includes any body parameters you send in

Sinnbeck's avatar

@drannagg no worries. If the problem is solved you can mark a best answer to set the thread as solved

Please or to participate in this conversation.