Skip to content

Commit

Permalink
Fix non-model children support
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-wtt committed Dec 5, 2021
1 parent d8bdf10 commit a69db42
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ public function resolveSoftDeletableRouteBinding($value, $field = null)
/**
* Retrieve the model for a bound value.
*
* @param Model|Relation $query
* @param Model|Relation $query
* @param mixed $value
* @param string|null $field
* @return Model|Illuminate\Database\Eloquent\Relations\Relation
Expand Down Expand Up @@ -1947,11 +1947,14 @@ protected function resolveChildRouteBindingQuery($childType, $value, $field)

if ($relationship instanceof HasManyThrough ||
$relationship instanceof BelongsToMany) {
return $relationship->getRelated()->resolveRouteBindingQuery(
$relationship, $value, $relationship->getRelated()->getTable().'.'.$field);
$field = $relationship->getRelated()->getTable().'.'.$field;
}

return $relationship->getRelated()->resolveRouteBindingQuery($relationship, $value, $field);
if ($relationship instanceof Model) {
return $relationship->getRelated()->resolveRouteBindingQuery($relationship, $value, $field);
}

return $relationship->where($field, $value);
}

/**
Expand Down

0 comments on commit a69db42

Please sign in to comment.