Tuesday, April 11, 2017

Just upgraded from laravel 5.2 to 5.4: return data with object

Look at the following expression:

        return $user->boxes()->get();

In my laravel 5.2 the data for the following example was:

boxes [
...array of boxes
]

Accessed by: response.json().boxes

since laravel 5.4 the returned data is only the array of the boxes:

[box1,box2,box3] without the "boxes" object above them.

Accessed by: response.json()

Because of this behavior, I have to change all my client api calls to get the array without thet object above it.

Is there any way to change it to work back as 5.2?



via TheUnreal

Advertisement