From 26ac235fe55070efe8e8ed451e30566973055e41 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Fri, 2 Oct 2020 08:42:01 -0400 Subject: [PATCH] Add new Inertia::location($url) method --- src/Inertia.php | 1 + src/ResponseFactory.php | 6 ++++++ tests/ResponseFactoryTest.php | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/Inertia.php b/src/Inertia.php index 09bc5b61..37d96075 100644 --- a/src/Inertia.php +++ b/src/Inertia.php @@ -11,6 +11,7 @@ * @method static void version($version) * @method static int|string getVersion() * @method static \Inertia\Response render($component, $props = []) + * @method static \Illuminate\Http\Response location($url) * * @see \Inertia\ResponseFactory */ diff --git a/src/ResponseFactory.php b/src/ResponseFactory.php index 1ccb42eb..350c9e2c 100644 --- a/src/ResponseFactory.php +++ b/src/ResponseFactory.php @@ -5,6 +5,7 @@ use Closure; use Illuminate\Support\Arr; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Response as BaseResponse; use Illuminate\Support\Traits\Macroable; use Illuminate\Contracts\Support\Arrayable; @@ -66,4 +67,9 @@ public function render($component, $props = []) $this->getVersion() ); } + + public function location($url) + { + return BaseResponse::make('', 409, ['X-Inertia-Location' => $url]); + } } diff --git a/tests/ResponseFactoryTest.php b/tests/ResponseFactoryTest.php index 4396a6b9..eb56e040 100644 --- a/tests/ResponseFactoryTest.php +++ b/tests/ResponseFactoryTest.php @@ -3,6 +3,7 @@ namespace Inertia\Tests; use Inertia\ResponseFactory; +use Illuminate\Http\Response; class ResponseFactoryTest extends TestCase { @@ -15,4 +16,13 @@ public function test_can_macro() $this->assertEquals('bar', $factory->foo()); } + + public function test_location_response() + { + $response = (new ResponseFactory())->location('https://inertiajs.com'); + + $this->assertInstanceOf(Response::class, $response); + $this->assertEquals(409, $response->getStatusCode()); + $this->assertEquals('https://inertiajs.com', $response->headers->get('X-Inertia-Location')); + } }