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
Copy file name to clipboardExpand all lines: core/subresources.md
+14-37Lines changed: 14 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,11 @@ If you're using the Doctrine or the Eloquent implementation, queries are automat
18
18
19
19
### Answer to a Question
20
20
21
+
> [!WARNING]
22
+
> This is not yet available with Laravel, you're welcome to contribute [on Github](github.com/api-platform/core)
23
+
24
+
---
25
+
21
26
> [!NOTE]
22
27
> In Symfony we use the term “entities”, while the following documentation is mostly for Laravel “models”.
23
28
@@ -237,6 +242,11 @@ resources:
237
242
238
243
### Company Employee's
239
244
245
+
> [!WARNING]
246
+
> This is not yet available with Laravel, you're welcome to contribute [on Github](github.com/api-platform/core)
247
+
248
+
---
249
+
240
250
> [!NOTE]
241
251
> In Symfony we use the term “entities”, while the following documentation is mostly for Laravel “models”.
242
252
@@ -265,8 +275,7 @@ use Doctrine\ORM\Mapping as ORM;
265
275
uriVariables: [
266
276
'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
267
277
'id' => new Link(fromClass: Employee::class),
268
-
],In Laravel
269
-
278
+
],
270
279
operations: [ new Get() ]
271
280
)]
272
281
#[ApiResource(
@@ -348,9 +357,10 @@ class Company {
348
357
349
358
## Security
350
359
351
-
In order to use Symfony's or the Laravel built-in security system on subresources the security option of the `Link` attribute can be used.
360
+
> [!WARNING]
361
+
> This is not yet available with Laravel, you're welcome to contribute [on Github](github.com/api-platform/core)
352
362
353
-
### Symfony example for security
363
+
In order to use Symfony's built-in security system on subresources the security option of the `Link` attribute can be used.
354
364
355
365
To restrict the access to a subresource based on the parent object simply use the Symfony expression language as you would do normally, with the exception that the name defined in `toProperty` or `fromProperty` is used to access the object.
356
366
@@ -374,44 +384,11 @@ class Company {
374
384
}
375
385
```
376
386
377
-
### Laravel example for security
378
-
379
-
With Laravel, we can use the following code:
380
-
381
-
```php
382
-
<?php
383
-
#[ApiResource(
384
-
uriTemplate: '/employees/{employeeId}/company',
385
-
uriVariables: [
386
-
'employeeId' => new Link(fromClass: Employee::class, toProperty: 'company', security: Gate::allows('some_voter', $company)),
387
-
],
388
-
operations: [
389
-
new Get()
390
-
]
391
-
)]
392
-
393
-
class Company {
394
-
// ...
395
-
}
396
-
```
397
-
398
387
This is currently an experimental feature disabled by default. To enable it please set `enable_link_security` to true:
399
388
400
-
### Symfony configuration to disable link security
401
389
402
390
```yaml
403
391
# api/config/packages/api_platform.yaml
404
392
api_platform:
405
393
enable_link_security: true
406
394
```
407
-
408
-
### Laravel configuration to disable link security
0 commit comments