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

Antonella's avatar

API STORE request->all() is empty in feature test

I have this method which makes the store in the db:

public function storeApi(Request $request)
	{
        $request=$request->all();
	dd($request);

... ..

when I call the api from feature test it gives me empty, let me explain:

$token = 'izjY6Y8fk8y4ztWuagfdaPzaszOvo1ix8ghvApUv9JRjMZP7PR';

    $data = [
        "title" => [
            "en" => "engl",
            "fr" => "francese",
            "it" => "ital"
        ],
        "body" => [
            "en" => "ndncidcdksncsdn",
            "fr" => "ndncidcdksncscddddddn",
            "it" => "ndncidcdksncscddddddn",
        ]
    ];

    //check article
    $response = $this->withHeaders([
        'Content-Type' => 'application/json',
        'Authorization' => 'Bearer '.$token,
    ])->post('/api/store',$data);

//$response is []

if instead I recall the method from api store with insomnia, it prints the data I sent it

I don't understand why the $ response doesn't take the parameters that I send it through post and instead I do it as it should be with insomnia
0 likes
9 replies
Nakov's avatar

@gianmarx probably because you are not returning any response.. Try this:

$request=$request->all();
return $request;

instead of dd() when making an API call.

Antonella's avatar

public function storeApi(Request $request) {

   ..

$request->all();

    //insert
    .....
    return response()->json($article, 201);
}

while from route api I call it like this:

Route::post('/store',[ArticleApiController::class,'storeApi']);
Nakov's avatar

You should not use $response->all() but $request->all() in your controller since what you are doing from an API is requesting data.

Antonella's avatar

sorry and a typo that's what i get:

the problem is this

 public function storeApi(Request $request)
{
    dd($request->all());//return void []

@nakov

Nakov's avatar

@gianmarx and I say it once again, don't use dd() for api testing, but use return instead:

return $request->all();
Antonella's avatar

I put a return $ request-> all (); I always get the usual result [] for feature test while if I call from insomnia I get the return of $ data. Unfortunately the substance does not change.

I don't understand why from TEst feature I always have an empty request-> all () unlike when I call the usual method with Insomnia

JAY_CHAUHAN's avatar

hi @gianmarx , In which file you can call this, i mean you write this in controller side or blade file. because if you use blade file then use AJAX

Code:

$headers: "Bearer".$token;

$data = [
        "title" => [
            "en" => "engl",
            "fr" => "francese",
            "it" => "ital"
        ],
        "body" => [
            "en" => "ndncidcdksncsdn",
            "fr" => "ndncidcdksncscddddddn",
            "it" => "ndncidcdksncscddddddn",
        ]
    ];
       	
$.ajax( {
    url:'/api/store',
    method:'POST',
    data: $data,
   headers: $headerParams,
    success: function( response ) {       
    },  
});
Antonella's avatar

no one I call it the feature Test side as follows:

$response = $this->withHeaders([
    'Content-Type' => 'application/json',
    'Authorization' => 'Bearer '.$token,
])->post('/api/store',$data);

getting an EMPTY request

and the other I call it with Insominia

return $data

the strange thing that if I delete $ request-> all () the api / store from insomnia still works the same

@nakov @jay_chauhan

Please or to participate in this conversation.