From f8af1166169d98a12af54aae8ceff87cea55bbbd Mon Sep 17 00:00:00 2001 From: Mathieu TUDISCO Date: Tue, 10 Oct 2017 17:09:07 +0200 Subject: [PATCH] Return 201 in case of a Model just created. --- src/Illuminate/Routing/Router.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Illuminate/Routing/Router.php b/src/Illuminate/Routing/Router.php index c2c61365afeb..b8b26ddfc997 100644 --- a/src/Illuminate/Routing/Router.php +++ b/src/Illuminate/Routing/Router.php @@ -11,6 +11,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Support\Collection; use Illuminate\Container\Container; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Traits\Macroable; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Events\Dispatcher; @@ -700,6 +701,8 @@ public static function toResponse($request, $response) if ($response instanceof PsrResponseInterface) { $response = (new HttpFoundationFactory)->createResponse($response); + } elseif ($response instanceof Model && $response->wasRecentlyCreated) { + $response = new JsonResponse($response, 201); } elseif (! $response instanceof SymfonyResponse && ($response instanceof Arrayable || $response instanceof Jsonable ||