Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Extract child route model relationship name into a method #43597

Merged
merged 3 commits into from Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Expand Up @@ -1980,7 +1980,7 @@ public function resolveSoftDeletableChildRouteBinding($childType, $value, $field
*/
protected function resolveChildRouteBindingQuery($childType, $value, $field)
{
$relationship = $this->{Str::plural(Str::camel($childType))}();
$relationship = $this->{$this->childRouteBindingRelationshipName($childType)}();

$field = $field ?: $relationship->getRelated()->getRouteKeyName();

Expand All @@ -1994,6 +1994,17 @@ protected function resolveChildRouteBindingQuery($childType, $value, $field)
: $relationship->getRelated()->resolveRouteBindingQuery($relationship, $value, $field);
}

/**
* Retrieve the child route model binding relationship name for the given child type.
*
* @param string $childType
* @return string
*/
protected function childRouteBindingRelationshipName($childType)
{
return Str::plural(Str::camel($childType));
}

/**
* Retrieve the model for a bound value.
*
Expand Down