How I got Laravel Precognition working #249
jameswagoner
started this conversation in
Show and tell
Replies: 1 comment
-
@jameswagoner |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I came across an issue about Precognition support when I ran into that issue recently and saw that there was no interest really in resolving it so I wanted to share how I solved it and possible get some feedback on it.
First I dug into what Precognition was doing when throwing its
Attempting to predict the outcome of the [{$class}::{$method}()] method but the method is not defined.
exception.In the PrecognitionControllerDispatcher class, you'll find
ensureMethodExists()
where it gets passed the$controller
and$method
that thehandle()
method was given.With how Laravel Actions uses decorators to keep your action classes clean,
$controller
ends up being the controller decorator instead of the class you defined in the route.Solution for me was to extend the HandlePrecognitiveRequests middleware and bind my own
PrecognitionControllerDispatcher
that passes the parsed controller class from the route definition.Beta Was this translation helpful? Give feedback.
All reactions