From 192944e00b409903a26fad65e5c84e5d82896c64 Mon Sep 17 00:00:00 2001 From: Vincent Amstoutz Date: Mon, 9 Dec 2024 14:54:01 +0100 Subject: [PATCH] docs(operation-path-naming): compatibility with laravel (#2088) --- core/operation-path-naming.md | 37 +++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/core/operation-path-naming.md b/core/operation-path-naming.md index 1433933ae3a..def62e3426b 100644 --- a/core/operation-path-naming.md +++ b/core/operation-path-naming.md @@ -8,11 +8,14 @@ Pre-registered resolvers are available and can easily be overridden. There are two pre-registered operation path naming services: | Service name | Entity name | Path result | -| -------------------------------------------------------------- | ------------ | --------------- | +|----------------------------------------------------------------|--------------|-----------------| | `api_platform.metadata.path_segment_name_generator.underscore` | `MyResource` | `/my_resources` | | `api_platform.metadata.path_segment_name_generator.dash` | `MyResource` | `/my-resources` | The default resolver is `api_platform.metadata.path_segment_name_generator.underscore`. + +### Configuration using Symfony + To change it to the dash resolver, add the following lines to `api/config/packages/api_platform.yaml`: ```yaml @@ -21,6 +24,19 @@ api_platform: path_segment_name_generator: api_platform.metadata.path_segment_name_generator.dash ``` +### Configuration using Laravel + +To change it to the dash resolver, add the following lines to `config/api-platform.php`: + +```php + 'api_platform.metadata.path_segment_name_generator.dash' +]; +``` + ## Create a Custom Operation Path Resolver 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 ```php App\Operation\SingularPathSegmentNameGenerator::class +]; +```