Skip to content

Commit

Permalink
Make implicit binding more generic.
Browse files Browse the repository at this point in the history
Allow any object implementing UrlRoutable to be implicitly resolved.
  • Loading branch information
taylorotwell committed Aug 20, 2017
1 parent bf0cb82 commit d911fa8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Str;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Contracts\Routing\BindingRegistrar;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
Expand Down Expand Up @@ -171,7 +172,7 @@ protected function resolveImplicitBindingIfPossible($key, $value, $callbackParam
protected function isImplicitlyBindable($key, $parameter)
{
return $parameter->name === $key && $parameter->getClass() &&
$parameter->getClass()->isSubclassOf(Model::class);
$parameter->getClass()->isSubclassOf(UrlRoutable::class);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Routing/ImplicitRouteBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class ImplicitRouteBinding
Expand All @@ -19,14 +20,14 @@ public static function resolveForRoute($container, $route)
{
$parameters = $route->parameters();

foreach ($route->signatureParameters(Model::class) as $parameter) {
foreach ($route->signatureParameters(UrlRoutable::class) as $parameter) {
if (! $parameterName = static::getParameterName($parameter->name, $parameters)) {
continue;
}

$parameterValue = $parameters[$parameterName];

if ($parameterValue instanceof Model) {
if ($parameterValue instanceof UrlRoutable) {
continue;
}

Expand Down

0 comments on commit d911fa8

Please sign in to comment.