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
Note that all we had to do is to set up `@ApiSubresource` on the `Question::answer` relation. Because the `answer` is a to-one relation, we know that this subresource is an item. Therefore the response will look like this:
107
+
Note that all we had to do is to set up `#[ApiSubresource]` on the `Question::answer` relation. Because the `answer` is a to-one relation, we know that this subresource is an item. Therefore the response will look like this:
108
108
109
109
```json
110
110
{
@@ -136,14 +136,16 @@ namespace App\Entity;
136
136
137
137
use ApiPlatform\Core\Annotation\ApiResource;
138
138
139
-
/**
140
-
* @ApiResource(subresourceOperations={
141
-
* "api_questions_answer_get_subresource"={
142
-
* "method"="GET",
143
-
* "normalization_context"={"groups"={"foobar"}}
144
-
* }
145
-
* })
146
-
*/
139
+
#[ApiResource(
140
+
subresourceOperations: [
141
+
'api_questions_answer_get_subresource': [
142
+
'method' => 'GET',
143
+
'normalization_context': [
144
+
'groups': ['foobar'],
145
+
],
146
+
],
147
+
],
148
+
)]
147
149
class Answer
148
150
{
149
151
// ...
@@ -198,17 +200,14 @@ You can control the path of subresources with the `path` option of the `subresou
198
200
<?php
199
201
// api/src/Entity/Question.php
200
202
201
-
/**
202
-
* ...
203
-
* @ApiResource(
204
-
* subresourceOperations={
205
-
* "api_questions_answer_get_subresource"={
206
-
* "method"="GET",
207
-
* "path"="/questions/{id}/all-answers"
208
-
* },
209
-
* },
210
-
* )
211
-
*/
203
+
#[ApiResource(
204
+
subresourceOperations: [
205
+
'api_questions_answer_get_subresource': [
206
+
'method' => 'GET',
207
+
'path' => '/questions/{id}/all-answers',
208
+
],
209
+
],
210
+
)]
212
211
class Question
213
212
{
214
213
}
@@ -222,16 +221,13 @@ The `subresourceOperations` attribute also allows you to add an access control o
222
221
<?php
223
222
// api/src/Entity/Answer.php
224
223
225
-
/**
226
-
* ...
227
-
* @ApiResource(
228
-
* subresourceOperations={
229
-
* "api_questions_answer_get_subresource"= {
230
-
* "security"="has_role('ROLE_AUTHENTICATED')"
231
-
* }
232
-
* }
233
-
* )
234
-
*/
224
+
#[ApiResource(
225
+
subresourceOperations: [
226
+
'api_questions_answer_get_subresource': [
227
+
'security' => "has_role('ROLE_AUTHENTICATED')",
228
+
],
229
+
],
230
+
)]
235
231
class Answer
236
232
{
237
233
}
@@ -250,16 +246,12 @@ use ApiPlatform\Core\Annotation\ApiProperty;
0 commit comments