Skip to content

Commit

Permalink
Return 201 in case of a Model just created. (#21625)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieutu authored and taylorotwell committed Oct 13, 2017
1 parent 9d2d010 commit bc54efd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ||
Expand Down

0 comments on commit bc54efd

Please sign in to comment.