You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found an issue with the documentation for API Resources, and I'd be happy to make PR to the docs repo to fix it, except that I'm not sure what the best way to fix it is.
First, the documentation for "Resource Collections" says:
use App\Http\Resources\UserResource;
use App\Models\User;
Route::get('/users', function () {
return UserResource::collection(User::all());
});
Note that this does not allow any addition of custom meta data that may need to be returned with your collection. If you would like to customize the resource collection response, you may create a dedicated resource to represent the collection:
That paragraph implies that this shouldn't work:
use App\Http\Resources\UserResource;
use App\Models\User;
Route::get('/users', function () {
return UserResource::collection(User::all())
->additional([
// add data here
]);
});
However, that works perfectly.
Does that mean this paragraph should be removed? The problem is that this paragraph serves as an introduction to creating dedicated Collection resources.
I tried to figure out how to reword it to submit a PR, but I can't seem to get it right.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I found an issue with the documentation for API Resources, and I'd be happy to make PR to the docs repo to fix it, except that I'm not sure what the best way to fix it is.
First, the documentation for "Resource Collections" says:
That paragraph implies that this shouldn't work:
However, that works perfectly.
Does that mean this paragraph should be removed? The problem is that this paragraph serves as an introduction to creating dedicated Collection resources.
I tried to figure out how to reword it to submit a PR, but I can't seem to get it right.
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions