Skip to content

Commit 26ac235

Browse files
committed
Add new Inertia::location($url) method
1 parent 2cee543 commit 26ac235

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Inertia.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @method static void version($version)
1212
* @method static int|string getVersion()
1313
* @method static \Inertia\Response render($component, $props = [])
14+
* @method static \Illuminate\Http\Response location($url)
1415
*
1516
* @see \Inertia\ResponseFactory
1617
*/

src/ResponseFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use Illuminate\Support\Arr;
77
use Illuminate\Support\Facades\App;
8+
use Illuminate\Support\Facades\Response as BaseResponse;
89
use Illuminate\Support\Traits\Macroable;
910
use Illuminate\Contracts\Support\Arrayable;
1011

@@ -66,4 +67,9 @@ public function render($component, $props = [])
6667
$this->getVersion()
6768
);
6869
}
70+
71+
public function location($url)
72+
{
73+
return BaseResponse::make('', 409, ['X-Inertia-Location' => $url]);
74+
}
6975
}

tests/ResponseFactoryTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Inertia\Tests;
44

55
use Inertia\ResponseFactory;
6+
use Illuminate\Http\Response;
67

78
class ResponseFactoryTest extends TestCase
89
{
@@ -15,4 +16,13 @@ public function test_can_macro()
1516

1617
$this->assertEquals('bar', $factory->foo());
1718
}
19+
20+
public function test_location_response()
21+
{
22+
$response = (new ResponseFactory())->location('https://inertiajs.com');
23+
24+
$this->assertInstanceOf(Response::class, $response);
25+
$this->assertEquals(409, $response->getStatusCode());
26+
$this->assertEquals('https://inertiajs.com', $response->headers->get('X-Inertia-Location'));
27+
}
1828
}

0 commit comments

Comments
 (0)