Skip to content

Commit 192944e

Browse files
docs(operation-path-naming): compatibility with laravel (#2088)
1 parent 7d0f6c7 commit 192944e

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

core/operation-path-naming.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ Pre-registered resolvers are available and can easily be overridden.
88
There are two pre-registered operation path naming services:
99

1010
| Service name | Entity name | Path result |
11-
| -------------------------------------------------------------- | ------------ | --------------- |
11+
|----------------------------------------------------------------|--------------|-----------------|
1212
| `api_platform.metadata.path_segment_name_generator.underscore` | `MyResource` | `/my_resources` |
1313
| `api_platform.metadata.path_segment_name_generator.dash` | `MyResource` | `/my-resources` |
1414

1515
The default resolver is `api_platform.metadata.path_segment_name_generator.underscore`.
16+
17+
### Configuration using Symfony
18+
1619
To change it to the dash resolver, add the following lines to `api/config/packages/api_platform.yaml`:
1720

1821
```yaml
@@ -21,6 +24,19 @@ api_platform:
2124
path_segment_name_generator: api_platform.metadata.path_segment_name_generator.dash
2225
```
2326
27+
### Configuration using Laravel
28+
29+
To change it to the dash resolver, add the following lines to `config/api-platform.php`:
30+
31+
```php
32+
<?php
33+
// config/api-platform.php
34+
return [
35+
// ....
36+
'path_segment_name_generator' => 'api_platform.metadata.path_segment_name_generator.dash'
37+
];
38+
```
39+
2440
## Create a Custom Operation Path Resolver
2541

2642
Let's assume we need URLs without separators (e.g. `api.tld/myresources`)
@@ -31,7 +47,7 @@ Make sure the custom segment generator implements [`ApiPlatform\Metadata\Operati
3147

3248
```php
3349
<?php
34-
// api/src/Operation/SingularPathSegmentNameGenerator.php
50+
// api/src/Operation/SingularPathSegmentNameGenerator.php with Symfony or app/Operation/SingularPathSegmentNameGenerator.php with Laravel
3551
namespace App\Operation;
3652
3753
use ApiPlatform\Metadata\Operation\PathSegmentNameGeneratorInterface;
@@ -61,7 +77,7 @@ class SingularPathSegmentNameGenerator implements PathSegmentNameGeneratorInterf
6177

6278
Note that `$name` contains a camelCase string, by default the resource class name (e.g. `MyResource`).
6379

64-
### Registering the Service
80+
### Registering the Service (for Symfony only)
6581

6682
If you haven't disabled the autowiring option, the service will be registered automatically and you have nothing more to
6783
do.
@@ -74,10 +90,23 @@ services:
7490
'App\Operation\SingularPathSegmentNameGenerator': ~
7591
```
7692

77-
### Configuring It
93+
### Configuring the Service
94+
95+
#### Configuring It using Symfony
7896

7997
```yaml
8098
# api/config/packages/api_platform.yaml
8199
api_platform:
82100
path_segment_name_generator: 'App\Operation\SingularPathSegmentNameGenerator'
83101
```
102+
103+
#### Configuring It using Laravel
104+
105+
```php
106+
<?php
107+
// config/api-platform.php
108+
return [
109+
// ....
110+
'path_segment_name_generator' => App\Operation\SingularPathSegmentNameGenerator::class
111+
];
112+
```

0 commit comments

Comments
 (0)