codecasts / spa-starter-kit

A highly opinionated starter kit for building Single Page Applications with Laravel and Vue.js
MIT License
913 stars 134 forks source link

Improve response #92

Closed flyingluscas closed 7 years ago

flyingluscas commented 7 years ago

The webservice responses API was improved, making more readable and more simple to use transformers.

Now to return a response from a controller you must use the new response property from the ApiController, see some examples below.

$this->response->json([
    'some kind' => 'of data',
]);

$this->response->collection($items, new MyTransformerClass);

$this->response->item($item, new MyTransformerClass);

$this->response->withTooManyRequests();

$this->response->withUnauthorized();

$this->response->withInternalServerError();

$this->response->withNotFound();

$this->response->withNoContent();

$this->response->withError('Some error message');