diff --git a/core/operations.md b/core/operations.md index a8ccd574fea..6239007ca39 100644 --- a/core/operations.md +++ b/core/operations.md @@ -63,6 +63,60 @@ Item operations: > properties not included in the payload are **not** removed, their current values are preserved. To > remove an existing property, its value must be explicitly set to `null`. +## Upsert: Creating a Resource With PUT + +By default, sending a `PUT` request to an item that does not exist returns a `404 Not Found`. To +enable an "upsert" behavior (update the resource if it exists, create it otherwise), set the +`allowCreate` property to `true` on the `PUT` operation. The identifier provided in the URI is then +used for the new resource and a `201 Created` response is returned when the item did not exist. + + + +```php + + + + + + + + + +``` + + + ## Enabling and Disabling Operations If no operation is specified, all default CRUD operations are automatically registered. It is also diff --git a/laravel/index.md b/laravel/index.md index 573d312f758..dfe58f2b890 100644 --- a/laravel/index.md +++ b/laravel/index.md @@ -734,7 +734,9 @@ You can change the default configuration (for instance, which operations are ena the config (`config/api-platform.php`). For the rest of this tutorial, we'll assume that at least all default operations are enabled (you -can also enable `PUT` if you want to support upsert operations). +can also enable `PUT`, optionally with +[`allowCreate: true`](../core/operations.md#upsert-creating-a-resource-with-put) if you want to +support upsert operations). ## Adding Filters