Skip to content

Commit

Permalink
[9.x] Extract child route model relationship name into a method (#43597)
Browse files Browse the repository at this point in the history
* Extract child route model relationship name

* Fix style

* Update Model.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
orkhanahmadov and taylorotwell committed Aug 8, 2022
1 parent e0d8284 commit 3ccf1b1
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 3ccf1b1

Please sign in to comment.