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

Princechrisvic's avatar

Laravel Api returning null

My Api is returning null. If I paste the API link on the browser, there will be no issue. It will return correctly but if I call the API through the Http::get, it will return null.

On the api.php, here is how the API look like

Route::get('/apitest', function () { return response( [ 'status'=>true, 'message'=>'Your Api response is working.' ] ); });

On the browser, it has no issue when I call https://example.com/api/apitest

However, my Controller , if I do Http::acceptJson()->get('https://example.net/api/apitest')->json(); It will return null. The Laravel version is 9.12.2 and the PHP version on the server is 8.1.

0 likes
1 reply
Nihir's avatar

Did you try after upgrading the PHP version? It looks perfect. Maybe there is a version issue. Or you can do this thing using the controller. It should be worked.

Please or to participate in this conversation.