Skip to content

Commit

Permalink
Use Laravel's Reflector class to get model parameter class name (#396)
Browse files Browse the repository at this point in the history
* Use Laravel Reflector to get model parameter type class name

* Fix for older versions of Laravel
  • Loading branch information
bakerkretzmar authored Jan 15, 2021
1 parent 8be42a1 commit 457eb03
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Ziggy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Support\Arr;
use Illuminate\Support\Reflector;
use Illuminate\Support\Str;
use JsonSerializable;
use ReflectionMethod;
Expand Down Expand Up @@ -155,7 +156,9 @@ private function resolveBindings(array $routes): array
$bindings = [];

foreach ($route->signatureParameters(UrlRoutable::class) as $parameter) {
$model = $parameter->getType()->getName();
$model = class_exists(Reflector::class)
? Reflector::getParameterClassName($parameter)
: $parameter->getType()->getName();
$override = $model === (new ReflectionMethod($model, 'getRouteKeyName'))->class;

// Avoid booting this model if it doesn't override the default route key name
Expand Down

0 comments on commit 457eb03

Please sign in to comment.