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

Bvanhaastrecht's avatar

Unable to retrieve request body with POST method

Hello,

Just banging my head on something very simple. I'm doing POST request with application/json RAW body data in Postman. I'm unable to get this JSON body data in Laravel.

Using Laravel 5.8 I should be seeing data in $request->getContent(), but it's empty.

Disabled CSRF, disabled every Middleware without success.

Any ideas?

Thanks, Bastiaan

0 likes
6 replies
tykus's avatar

getContent() will return a string of JSON, where $request->all() will give you an associative array with the keys and values from the JSON payload

Bvanhaastrecht's avatar

Thanks, but the string of getContent() is empty, and so is all().

tykus's avatar

How are you checking the request?

Bvanhaastrecht's avatar

api.php

Route::post('/', 'BaseController@apiRoot');

BaseController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BaseController extends Controller
{
    public function apiRoot(Request $request)
    {
       var_dump($request->getContent());
       exit;
    }
}

As you can see I'm trying to get POST from api root directory. Just tested with an nested directory, and this does contain POST body. So the issue is only when trying to get body from root of /api/.

Because of migration from a non-laravel to Laravel app I need to have POST with body in API root.

Bvanhaastrecht's avatar
Bvanhaastrecht
OP
Best Answer
Level 1

Got it, using trailing slash I get no body, with no trailing slash it works.

Works:

POST https://url/api

No body:

POST https://url/api/

Is this as expected?

HashmatWaziri's avatar

jQuery.ajax({ url: "{{ url("register") }}", type: "POST", dataType: "json", data:$('#registerForm').serializeArray(), success: function(data,textStatus, xhr){...}

Please or to participate in this conversation.