Skip to content

Commit 83c8397

Browse files
docs(url-generation-strategy): compatibility with laravel (#2089)
1 parent 0bbc490 commit 83c8397

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

core/url-generation-strategy.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,42 @@ For instance, in JSON-LD, you will get a collection like this:
2222

2323
You may want to use absolute URLs (for instance if resources are used in another API) or network paths instead.
2424

25-
It can be configured globally:
25+
## Configure URL Generation Globally
26+
27+
It can be configured globally using one of the configurations below:
28+
29+
### Configure URL Generation Globally using Symfony
2630

2731
```yaml
2832
# api/config/packages/api_platform.yaml
2933
api_platform:
3034
defaults:
3135
url_generation_strategy: !php/const ApiPlatform\Api\UrlGeneratorInterface::ABS_URL
3236
```
37+
### Configure URL Generation Globally using Laravel
38+
39+
```php
40+
<?php
41+
// config/api-platform.php
42+
return [
43+
// ....
44+
'defaults' => [
45+
'url_generation_strategy' => ApiPlatform\Api\UrlGeneratorInterface::ABS_URL
46+
],
47+
];
48+
```
49+
50+
## Configure URL Generation for a Specific Resource
3351

3452
It can also be configured only for a specific resource:
3553

3654
<code-selector>
3755

3856
```php
3957
<?php
40-
// api/src/Entity/Book.php
58+
// api/src/ApiResource/Book.php with Symfony or app/ApiResource/Book.php with Laravel
59+
60+
namespace App\ApiResource;
4161

4262
use ApiPlatform\Metadata\ApiResource;
4363
use ApiPlatform\Api\UrlGeneratorInterface;
@@ -51,21 +71,23 @@ class Book
5171

5272
```yaml
5373
# api/config/api_platform/resources.yaml
74+
# The YAML syntax is only supported for Symfony
5475
resources:
55-
App\Entity\Book:
76+
App\ApiResource\Book:
5677
urlGenerationStrategy: !php/const ApiPlatform\Api\UrlGeneratorInterface::ABS_URL
5778
```
5879
5980
```xml
6081
<?xml version="1.0" encoding="UTF-8" ?>
6182
<!-- api/config/api_platform/resources.xml -->
83+
<!-- The XML syntax is only supported for Symfony -->
6284

6385
<resources
6486
xmlns="https://api-platform.com/schema/metadata/resources-3.0"
6587
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6688
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
6789
https://api-platform.com/schema/metadata/resources-3.0.xsd">
68-
<resource class="App\Entity\Book" urlGenerationStrategy="0" />
90+
<resource class="App\ApiResource\Book" urlGenerationStrategy="0" />
6991
</resources>
7092
```
7193

0 commit comments

Comments
 (0)