Skip to content

Commit

Permalink
Merge pull request #154 from inertiajs/location
Browse files Browse the repository at this point in the history
Add new Inertia::location($url) method
  • Loading branch information
reinink authored Oct 2, 2020
2 parents 2cee543 + 26ac235 commit 3db77cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Inertia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 6 additions & 0 deletions src/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,4 +67,9 @@ public function render($component, $props = [])
$this->getVersion()
);
}

public function location($url)
{
return BaseResponse::make('', 409, ['X-Inertia-Location' => $url]);
}
}
10 changes: 10 additions & 0 deletions tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inertia\Tests;

use Inertia\ResponseFactory;
use Illuminate\Http\Response;

class ResponseFactoryTest extends TestCase
{
Expand All @@ -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'));
}
}

0 comments on commit 3db77cb

Please sign in to comment.