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

Shivamyadav's avatar

can I get the explanation of the code from the if() conditional to session ()?

 public function store()
    {
        $attributes = request()->validate([
            'email' => 'required|email',
            'password' => 'required'
        ]);

        if (! auth()->attempt($attributes)) {
            throw ValidationException::withMessages([
                'email' => 'Your provided credentials email/password could not be verified.'
            ]);
        }

        session()->regenerate();

        return redirect('/')->with('success', 'Welcome Back!');
    }
0 likes
5 replies
Tray2's avatar

What is there to explain, it throws an exception if the auth attempt fails.

Shivamyadav's avatar

@Tray2 I need to know about the function auth()->attempt () and sessions ()->regenerated ()

Lara_Love's avatar

is your means:

public function store()
    {
        $attributes = request()->validate([
            'email' => 'required|email',
            'password' => 'required'
        ]);

        if (! auth()->attempt($attributes)) {
            throw ValidationException::withMessages([
                'email' => 'Your provided credentials email/password could not be verified.'
            ]);
        }

        session()->regenerate();
session()->flash('success', 'This message ??');
        return redirect('/')->with('success', 'Welcome Back!');
    }

Please or to participate in this conversation.