diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasUniqueStringIds.php b/src/Illuminate/Database/Eloquent/Concerns/HasUniqueStringIds.php index ae86c43042d5..fa50265b2d23 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasUniqueStringIds.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasUniqueStringIds.php @@ -54,11 +54,11 @@ public function uniqueIds() public function resolveRouteBindingQuery($query, $value, $field = null) { if ($field && in_array($field, $this->uniqueIds()) && ! $this->isValidUniqueId($value)) { - throw (new ModelNotFoundException)->setModel(get_class($this), $value); + $this->handleInvalidUniqueId($value, $field); } if (! $field && in_array($this->getRouteKeyName(), $this->uniqueIds()) && ! $this->isValidUniqueId($value)) { - throw (new ModelNotFoundException)->setModel(get_class($this), $value); + $this->handleInvalidUniqueId($value, $field); } return parent::resolveRouteBindingQuery($query, $value, $field); @@ -91,4 +91,18 @@ public function getIncrementing() return $this->incrementing; } + + /** + * Throw an exception for the given invalid unique ID. + * + * @param mixed $value + * @param string|null $field + * @return never + * + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ + protected function handleInvalidUniqueId($value, $field) + { + throw (new ModelNotFoundException)->setModel(get_class($this), $value); + } }