Skip to content

Commit 9f68dc7

Browse files
authored
Fix camel casing relationship (#32217)
1 parent db36649 commit 9f68dc7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ public function resolveRouteBinding($value, $field = null)
15201520
*/
15211521
public function resolveChildRouteBinding($childType, $value, $field)
15221522
{
1523-
return $this->{Str::plural($childType)}()->where($field, $value)->first();
1523+
return $this->{Str::plural(Str::camel($childType))}()->where($field, $value)->first();
15241524
}
15251525

15261526
/**

tests/Routing/RoutingRouteTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,23 @@ public function testParentChildImplicitBindings()
16161616
$this->assertSame('1|test-slug', $router->dispatch(Request::create('foo/1/test-slug', 'GET'))->getContent());
16171617
}
16181618

1619+
public function testParentChildImplicitBindingsProperlyCamelCased()
1620+
{
1621+
$router = $this->getRouter();
1622+
1623+
$router->get('foo/{user}/{test_team:id}', [
1624+
'middleware' => SubstituteBindings::class,
1625+
'uses' => function (RoutingTestUserModel $user, RoutingTestTeamModel $testTeam) {
1626+
$this->assertInstanceOf(RoutingTestUserModel::class, $user);
1627+
$this->assertInstanceOf(RoutingTestTeamModel::class, $testTeam);
1628+
1629+
return $user->value.'|'.$testTeam->value;
1630+
},
1631+
]);
1632+
1633+
$this->assertSame('1|4', $router->dispatch(Request::create('foo/1/4', 'GET'))->getContent());
1634+
}
1635+
16191636
public function testImplicitBindingsWithOptionalParameterWithExistingKeyInUri()
16201637
{
16211638
$router = $this->getRouter();
@@ -2124,6 +2141,11 @@ public function posts()
21242141
return new RoutingTestPostModel;
21252142
}
21262143

2144+
public function testTeams()
2145+
{
2146+
return new RoutingTestTeamModel;
2147+
}
2148+
21272149
public function getRouteKeyName()
21282150
{
21292151
return 'id';

0 commit comments

Comments
 (0)