Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NoTimeForCaution's avatar

Auth Register Redirect upon FAIL

I'm trying to add a redirect back with flash to the registration page.

Essentially, in RegisterController I'm using:

if request('value') != 'value' then redirect back to /register

Any ideas on how to complete this task?

I get "Call to undefined method Illuminate\Http\RedirectResponse::validate()" when using:

flash('my_flash_message');
return back();
0 likes
3 replies
adibhanna's avatar

maybe you can use something like:

return redirect()->back()->with(['my_flash_message' => 'my message']);
Snapey's avatar
Snapey
Best Answer
Level 122

It depends where you put that code...

You should copy this from the registersUsers trait into your register controller and then modify it;


    /**
     * Handle a registration request for the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function register(Request $request)
    {
        $this->validator($request->all())->validate();

        // your new code here
        if($request->value != 'value') {
            flash('my_flash_message');
            return back();
        }
        // end of your code

        event(new Registered($user = $this->create($request->all())));

        $this->guard()->login($user);

        return $this->registered($request, $user)
                        ?: redirect($this->redirectPath());
    }

Please or to participate in this conversation.