nova-breadcrumbs
nova-breadcrumbs copied to clipboard
Use getControllerClass() instead of getController()
route()->getController()
is completely unsafe to use if the route uses a closure, and route()->isControllerAction() is protected. This leads to errors like BindingResolutionException: Target class [] does not exist.
if a tool uses closures instead of controllers as they are turned into serialized closures. Therefore, the following code does not handle the cases correctly:
if (array_key_exists("uses", $request->route()->action) && $request->route()->action['uses'] instanceof Closure) {
return $next($request);
}
The function getControllerClass()
is protected by the following function (in Illuminate\Routing\Route
):
/**
* Checks whether the route's action is a controller.
*
* @return bool
*/
protected function isControllerAction()
{
return is_string($this->action['uses']) && ! $this->isSerializedClosure();
}
I have rewritten the two occurrences of route()->getController()
to use getControllerClass()
instead.
Reference: https://github.com/wdelfuego/nova-calendar/issues/41#issuecomment-1326471351