Change resourceKey when using withPaginator
- Dominant language
- PHP
- Stars
- 9.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Hello
I'm new to api but as i saw, when i list all my users in a normal way i have a response like that
`"users" : [ ... ]`
Okay for that, ember.js models like this everything is ok because my resourcekey is the same as my model.
I wanna use the pagination, so i use
```
$users = User::paginate(50);
return $this->response->withPaginator($users, new UserTransformer);
```
My transformer look like
```
use App\User;
use League\Fractal;
class UserTransformer extends Fractal\TransformerAbstract
{
public function transform(User $user)
{
return [
'username' => $user->username,
];
}
}
```
But it return me the json with "data" resourcekey
```
{
"data": [
{
"username": "superuser"
},
{
"username": "administrator"
}
],
"meta": {
"pagination": {
"total": 2,
"count": 2,
"per_page": 50,
"current_page": 1,
"total_pages": 1,
"links": []
}
}
}
```
Is it possible to change the resource key to "users" ?
Should i change the resource key or api guidelines only recommend a "data" resourcekey ?
I don't know if ember will like to have a "data" resource key for user listing when all other requests respond with "users" : [].
Contributor guide
Research direction
Start from the withPaginator call shown in the issue and reproduce it with User::paginate(50) and UserTransformer. Compare the paginated response with the normal users response, then verify whether the resource key can be changed while preserving the pagination metadata. Done means the response uses the requested users key consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100