Closed yttrian closed 1 year ago
@yttrian Interesting. I was going to say that Laravel doesn't set the redirectTo
, but I found this in the source which indicates it sets it if you're using form requests, which seems to be the case here..
It looks like you may be able to override the getRedirectUrl
in the form request in the meantime.
We only have tests using simple request validation (here) so that does look like a bug. I think we may just change the middleware to use the guessed route (if it exists) instead then... 🤔
@yttrian a new version (1.12.0) was released with the fix for that. Thanks for reporting it.
Thanks for getting this fixed!
From my understanding, when request validation fails, the
TurboMiddleware
is supposed to redirect to the guessed route if it exists, but sinceValidationException
sets aredirectTo
, it is used instead of trying toguessFormRedirectUrl
.https://github.com/hotwired-laravel/turbo-laravel/blob/300bacc76aa8181c51311560a652e3c45faa25f1/src/Http/Middleware/TurboMiddleware.php#L102-L109
Consider this example that models my situation.
The view for
something.index
contains a frame with the contents ofsomething.create
which is a form with action pointing to the store route and method POST.When the form is submitted and validation fails it tries to
handleRedirectInterally
withsomething.index
because that's what theValidationException
says to do when insteadguessFormRedirectUrl
would correctly say to use the content ofsomething.create
.I'm basing this on comparing the debugger output of
$formRedirectUrl
versus$this->guessFormRedirectUrl($request)
with a breakpoint at line 91 in TurboMiddleware.phpI am using Laravel 10 if that's relevant.