Skip to content

Commit

Permalink
Add ability to generate a signed route with a routable parameter (#23584
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mattdfloyd authored and taylorotwell committed Mar 17, 2018
1 parent e36cacd commit 12ebdee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ public function formatScheme($secure)
*/
public function signedRoute($name, $parameters = [], $expiration = null)
{
$parameters = $this->formatParameters($parameters);

if ($expiration) {
$parameters = $parameters + ['expires' => $this->availableAt($expiration)];
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Integration/Routing/UrlSigningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Route;
use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Routing\Middleware\ValidateSignature;

/**
Expand Down Expand Up @@ -62,4 +63,37 @@ public function test_signed_middleware_with_invalid_url()
$response = $this->get($url);
$response->assertStatus(401);
}

public function test_signed_middleware_with_routable_parameter()
{
$model = new RoutableInterfaceStub;
$model->routable = 'routable';

Route::get('/foo/{bar}', function (Request $request, $routable) {
return $request->hasValidSignature() ? $routable : 'invalid';
})->name('foo');

$this->assertTrue(is_string($url = URL::signedRoute('foo', $model)));
$this->assertEquals('routable', $this->get($url)->original);
}
}

class RoutableInterfaceStub implements UrlRoutable
{
public $key;

public function getRouteKey()
{
return $this->{$this->getRouteKeyName()};
}

public function getRouteKeyName()
{
return 'routable';
}

public function resolveRouteBinding($routeKey)
{
//
}
}

0 comments on commit 12ebdee

Please sign in to comment.