ellipsesynergie / api-response

Simple package to handle response properly in your API.
MIT License
377 stars 53 forks source link

Return response from Laravel's Handler (now that api() macro is deprecated) #28

Closed jonagoldman closed 8 years ago

jonagoldman commented 8 years ago

Now that the api() macro is deprecated, I want to know how to return a response from Laravel's exception handler (Exceptions/Handler).

In the past, I used something like this

// inside the render() method in Handler.php

if ($e instanceof ApiException) {
    return response()->api()->withError($e->getMessage(), $e->getCode());
}

How can I avoid using api() ?

ps: sorry for not using the guidelines.

maximebeaudoin commented 8 years ago

@jonagoldman Personaly, in my Handler.php file i use the response object like this

$response = app(\EllipseSynergie\ApiResponse\Contracts\Response::class);

if ($e instanceof ValidatorException) {
    return $response->errorWrongArgsValidator($e->errors());
};
jonagoldman commented 8 years ago

Thanks will try it out!