diff --git a/src/Renderers/Twinkle.php b/src/Renderers/Twinkle.php index 6c1f175..abac5f7 100644 --- a/src/Renderers/Twinkle.php +++ b/src/Renderers/Twinkle.php @@ -109,11 +109,23 @@ protected function enrichData() * 1. Get route parameter value (our model route key value). * 2. Get route key name from the model. * 3. Query the DB to get the Model with that key name. + * */ + $modelValue = $routeParameters[$parameter]; - $routeKey = (new $class)->getRouteKeyName(); - $modelInstance = $class::where($routeKey, $modelValue)->firstOrFail(); - $extraArguments[$parameter] = $modelInstance; + + /** + * In case the parent controller in the flame already uses implicit + * route binding, then the parameters that arrive to the twinkle will + * already be model objects and not string values. Let's check that... + */ + if (is_object($modelValue) && is_subclass_of($modelValue, 'Illuminate\Database\Eloquent\Model')) { + $extraArguments[$parameter] = $modelValue; + } else { + $routeKey = (new $class)->getRouteKeyName(); + $modelInstance = $class::where($routeKey, $modelValue)->firstOrFail(); + $extraArguments[$parameter] = $modelInstance; + } } } else { $extraArguments[$parameter] = app()->make($class);