Skip to content

Update eloquent-resources.md #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions eloquent-resources.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
git: 3a2fa3ea59532f3239ae737ae78d0ffd1922c4c8
git: 0790883cb65b64c49bcdca57b5d114bf2ccb5abb
---

# Eloquent · Ресурсы API (Resource)
Expand Down Expand Up @@ -730,9 +730,9 @@ php artisan make:resource UserCollection
Вы также можете добавить данные верхнего уровня при создании экземпляров ресурсов в своем маршруте или контроллере. Метод `additional`, доступный для всех ресурсов, принимает массив данных, которые должны быть добавлены в ответ ресурса:

return (new UserCollection(User::all()->load('roles')))
->additional(['meta' => [
'key' => 'value',
]]);
->additional(['meta' => [
'key' => 'value',
]]);

<a name="resource-responses"></a>
## Ответы ресурса
Expand All @@ -753,8 +753,8 @@ php artisan make:resource UserCollection

Route::get('/user', function () {
return (new UserResource(User::find(1)))
->response()
->header('X-Value', 'True');
->response()
->header('X-Value', 'True');
});

В качестве альтернативы вы можете определить метод `withResponse` внутри самого ресурса. Этот метод будет вызываться, только когда ресурс будет возвращен как самый верхний ресурс в ответе:
Expand Down