mardi 1 mai 2018

How to use Laravel response()->json() to return empty object instead of empty array

In Laravel 5.5

Route::get('/test2', function (){
    $data = (object) [];

    return response()->json($data);

});

it always returns [] rather than {}.


another code:

Route::get('/test2', function (){
    $data = (object) [];

    return json_encode($data);

});

it correctly returns {}


I want to use response()->json() helper to return empty object instead of empty array, is it possible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire