Back

[5.4] clear error message back when going back a page after Session::reflash()


Hi,

I've got a 2 stage form using LaravelCollective forms and I use Session::reflash() in my controller actions to keep the form data if I refresh the page

The problem is this also keeps my errors from Form Page 2 if I hit the back button on the browser to go back to Form Page 1, after submitting Form Page 2 with errors

(ie Form Page 2's errors are showing on Form Page 1 because the messagebag still has the errors in the session)

is there a way to clear the errors message bag session, before the view is rendered?

(I can check with Form Page I'm on in order to not clear then for the same page)

thanks J

jmp909 replied 4 months ago

for now I've done it like this

$view = view('forms.register')->with($params); // will get $errors from message bag
if($shouldClearErrors) {
    $view = $view->withErrors(null); // will null out $errors
}
return $view;

but would be grateful for any other suggestions

thanks


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us