Closed vincent-lu closed 5 years ago
Hi
I have actually never seen what you describe, in fact there is a unit test in dingo which implies this is not the way it's meant to work.
Are you able to provide a simple test repository with laravel 5.4 and dingo only, with no other customisations to demonstrate this?
In any case, I think the way it does it now should be the correct way to do it.
Thanks for getting back to me @specialtactics. Since we have already updated all our code to accommodate this difference (whatever caused the change) let's close this issue.
Actual Behaviour
In Laravel 5.4 when returning a single Eloquent model as response from controller, the response is treated as EloquentModel by
Dingo\Api\Http\Response::morph()
; however after upgrading to Laravel 5.5 or 5.6, it is treated as an a type of array (array, ArrayObject or Arrayable).Because the default Json Formatter's
formatEloquentModel
will put the resulting array inside the singular name of the table; whileformatArray
will not, this leads to difference in response structure after upgrading from Laravel 5.4 to 5.5.Here is an example,
In Laravel 5.4, if returning
User::find(1)
, the JSON result is something like:But in Laravel 5.5, the same response from the controller results in:
This might be caused by the change in how Laravel return its originalContent. In
Dingo\Api\Http\Response::morph()
, while in Laravel 5.4 the$this->content = $this->getOriginalContent()
call returns a model object if the controller response is such; but in Laravel 5.5 the same line returns an array.Expected Behaviour
The JSON structure should remain the same after upgrading Laravel framework.
Steps to Reproduce
Will provide more details as needed.