Skip to content

Resources are not fully returned #2

@dimzeta

Description

@dimzeta

Hi, first of all thank you for you package, it helps me a lot.

I'm using it with Laravel Resources, and instead having the whole content, I only got the data content.

I don't know if it's really a bug of a feature, since this package is mainly based of Laravel response helper, but I thought it could be usefull to inform you (and others) about this behavior.
So I just don't use ok() when I return Resources and everything is ok.

Example:

class SerieIndexController extends Controller
{
    public function __invoke(Request $request)
    {
        $list = Serie::paginate();
        return SerieIndexResource::collection($list);
    }
}

Result:

{
  "data": [
    {
      "id": 1,
      "name": "aliquid nemo",
      "released_at": "1971-01-06T09:07:23.000000Z",
      "created_at": "2020-11-21T17:27:23.000000Z",
      "updated_at": "2020-11-21T17:27:23.000000Z",
      "deleted_at": null
    },
    {
      "id": 2,
      "name": "sint et",
      "released_at": "1971-02-19T21:51:30.000000Z",
      "created_at": "2020-11-21T17:27:23.000000Z",
      "updated_at": "2020-11-21T17:27:23.000000Z",
      "deleted_at": null
    },
    {
      "id": 3,
      "name": "pariatur optio",
      "released_at": "1981-09-03T16:15:32.000000Z",
      "created_at": "2020-11-21T17:27:23.000000Z",
      "updated_at": "2020-11-21T17:27:23.000000Z",
      "deleted_at": null
    }
  ],
  "links": {
    "first": "http://localhost/api/series?page=1",
    "last": "http://localhost/api/series?page=1",
    "prev": null,
    "next": null
  },
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 1,
    "links": [
      {
        "url": null,
        "label": "« Previous",
        "active": false
      },
      {
        "url": "http://localhost/api/series?page=1",
        "label": 1,
        "active": true
      },
      {
        "url": null,
        "label": "Next »",
        "active": false
      }
    ],
    "path": "http://localhost/api/series",
    "per_page": 15,
    "to": 3,
    "total": 3
  }
}

With response-helper:

class SerieShowController extends Controller
{
    public function __invoke(Request $request, Serie $serie)
    {
        return ok(new SerieDetailsResource($serie));
    }
}

Result:

[
  {
    "id": 1,
    "name": "aliquid nemo",
    "released_at": "1971-01-06T09:07:23.000000Z",
    "created_at": "2020-11-21T17:27:23.000000Z",
    "updated_at": "2020-11-21T17:27:23.000000Z",
    "deleted_at": null
  },
  {
    "id": 2,
    "name": "sint et",
    "released_at": "1971-02-19T21:51:30.000000Z",
    "created_at": "2020-11-21T17:27:23.000000Z",
    "updated_at": "2020-11-21T17:27:23.000000Z",
    "deleted_at": null
  },
  {
    "id": 3,
    "name": "pariatur optio",
    "released_at": "1981-09-03T16:15:32.000000Z",
    "created_at": "2020-11-21T17:27:23.000000Z",
    "updated_at": "2020-11-21T17:27:23.000000Z",
    "deleted_at": null
  }
]

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions