Skip to content

Commit 4ae31a1

Browse files
committed
clean up code
1 parent 312f446 commit 4ae31a1

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/Illuminate/Routing/ImplicitRouteBinding.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,33 @@ public static function resolveForRoute($container, $route)
1818
$parameters = $route->parameters();
1919

2020
foreach ($route->signatureParameters(Model::class) as $parameter) {
21-
$class = $parameter->getClass();
22-
23-
if (! $route->parameter($parameter->name) instanceof Model) {
24-
$model = $container->make($class->name);
21+
if ($route->parameter($parameter->name) instanceof Model) {
22+
continue;
23+
}
2524

26-
$parameterName = array_key_exists($parameter->name, $parameters) ? $parameter->name : null;
25+
$model = $container->make($parameter->getClass()->name);
2726

28-
// check if parameter name used was camelized in routed callback method
29-
if (! $parameterName) {
30-
$snakeParamName = snake_case($parameter->name);
31-
$parameterName = array_key_exists($snakeParamName, $parameters) ? $snakeParamName : null;
32-
}
27+
$parameterName = static::checkForParameter($parameter->name, $parameters) ?:
28+
static::checkForParameter(snake_case($parameter->name), $parameters);
3329

34-
if ($parameterName) {
35-
$value = $model->where($model->getRouteKeyName(), $parameters[$parameterName])->firstOrFail();
36-
$route->setParameter($parameterName, $value);
37-
}
30+
if ($parameterName) {
31+
$route->setParameter($parameterName, $model->where(
32+
$model->getRouteKeyName(), $parameters[$parameterName]
33+
)->firstOrFail());
3834
}
3935
}
4036
}
37+
38+
/**
39+
* Return the parameter name if it exists in the given parameters.
40+
*
41+
* @param string $name
42+
* @param array $parameters
43+
* @return string|null
44+
*/
45+
protected static function checkForParameter($name, $parameters)
46+
{
47+
return array_key_exists($name, $parameters)
48+
? $name : null;
49+
}
4150
}

tests/Routing/RoutingRouteTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ public function testModelBindingWithBindingClosure()
700700
$this->assertEquals('tayloralt', $router->dispatch(Request::create('foo/TAYLOR', 'GET'))->getContent());
701701
}
702702

703+
/**
704+
* @group shit
705+
*/
703706
public function testModelBindingWithCompoundParameterName()
704707
{
705708
$router = $this->getRouter();

0 commit comments

Comments
 (0)