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?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FvvtmF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire