Skip to content

Commit

Permalink
use table name when resolving has many through / one relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 30, 2020
1 parent 1e84161 commit 8d69454
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection as BaseCollection;
Expand Down Expand Up @@ -1522,7 +1523,13 @@ public function resolveRouteBinding($value, $field = null)
*/
public function resolveChildRouteBinding($childType, $value, $field)
{
return $this->{Str::plural(Str::camel($childType))}()->where($field, $value)->first();
$relationship = $this->{Str::plural(Str::camel($childType))}();

if ($relationship instanceof HasManyThrough) {
return $relationship->where($relationship->getRelated()->getTable().'.'.$field, $value)->first();
} else {
return $relationship->where($field, $value)->first();
}
}

/**
Expand Down

0 comments on commit 8d69454

Please sign in to comment.