Skip to content

Commit

Permalink
add support for LiveWire component urls
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Nov 13, 2020
1 parent 482384a commit 3b3403f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `ignition` will be documented in this file

## 2.5.1 - 2020-11-13

- add support for LiveWire component urls

## 2.5.0 - 2020-10-27

- add PHP 8.0-dev support
Expand Down
12 changes: 12 additions & 0 deletions src/Context/LaravelRequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public function getRoute(): array
];
}

public function getRequest(): array
{
$properties = parent::getRequest();


if ($this->request->hasHeader('x-livewire') && $this->request->hasHeader('referer')) {
$properties['url'] = $this->request->header('referer');
}

return $properties;
}

protected function getRouteParameters(): array
{
try {
Expand Down
15 changes: 15 additions & 0 deletions tests/Context/LaravelRequestContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ public function it_returns_the_url()
$this->assertSame('http://localhost/route', $request['url']);
}

/** @test */
public function it_returns_the_referer_url_if_it_is_an_livewire_request()
{
$request = $this->createRequest('GET', '/route', []);

$request->headers->set('x-livewire', true);
$request->headers->set('referer', 'http://localhost/referred');

$context = new LaravelRequestContext($request);

$request = $context->getRequest();

$this->assertSame('http://localhost/referred', $request['url']);
}

/** @test */
public function it_returns_the_cookies()
{
Expand Down

0 comments on commit 3b3403f

Please sign in to comment.