Search code examples
laravellaravel-authorization

Dingo api $response is undefined


Getting error

"message": "Undefined property: App\Http\Controllers\Api\ApiUserXYzController::$response"

return $this->response->collection($user_list, new ProjectTransformer())->setStatusCode(200);

I"m tring to transform the data but i'm getting $response is not defined. please guide


Solution

  • You forgot to include the helper trait that the docs tell you to use if you want the response builder at the property response on the controller.

    Dingo Wiki - Responses - Response Builder

    use Dingo\Api\Routing\Helpers;
    
    class SomeController ....
    {
        use Helpers;
        ...
    }