Skip to content

Commit 8d69454

Browse files
committed
use table name when resolving has many through / one relationships
1 parent 1e84161 commit 8d69454

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Illuminate/Database/Eloquent/Model.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Contracts\Support\Jsonable;
1212
use Illuminate\Database\ConnectionResolverInterface as Resolver;
1313
use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot;
14+
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
1415
use Illuminate\Database\Eloquent\Relations\Pivot;
1516
use Illuminate\Support\Arr;
1617
use Illuminate\Support\Collection as BaseCollection;
@@ -1522,7 +1523,13 @@ public function resolveRouteBinding($value, $field = null)
15221523
*/
15231524
public function resolveChildRouteBinding($childType, $value, $field)
15241525
{
1525-
return $this->{Str::plural(Str::camel($childType))}()->where($field, $value)->first();
1526+
$relationship = $this->{Str::plural(Str::camel($childType))}();
1527+
1528+
if ($relationship instanceof HasManyThrough) {
1529+
return $relationship->where($relationship->getRelated()->getTable().'.'.$field, $value)->first();
1530+
} else {
1531+
return $relationship->where($field, $value)->first();
1532+
}
15261533
}
15271534

15281535
/**

0 commit comments

Comments
 (0)