Skip to content

Conversation

@Hannoma
Copy link

@Hannoma Hannoma commented Nov 29, 2023

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: wdelfuego/nova-calendar#41 (comment)

…ly unsafe to use if the route uses a closure
@Hannoma
Copy link
Author

Hannoma commented Nov 29, 2023

This should also fix the problems described in #38

@benedict-w
Copy link

I also get an error with cached routes with tools as described here: #40, does this resolve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants