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

oliverreese10's avatar

Login Account with Something Else

Hi,

I want to implment login for Admins and Students, and they are in two separate tables. However, the Students will be logged in with their Students Code and Exam Code, and not using Username and Password. How can I accomplish this?

Anyone have a reference or tutorial that I can follow?

I have successfully make Admin can login with a Username and Password, but with Students that login without Password, it gives me an error.

I have made guards for both Admins and Students, and when I want to display their attributes on Blade I just type {{ auth()->guard('admin')->user()->username }}.

And on the Login Admin Controller, I have this code to make Admin can login

public function login(Request $request)
    {
        if (auth()->guard('admin')->attempt(['email' => $request->email, 'password' => $request->password])) {
            //dd(auth()->guard('admin')->user());
            return redirect(route('admin.dashboard'));
        } else {
            return back()->withErrors(['email' => 'Email or password are wrong.']);
        }
    }

However, to use the same function for Students that login with their Students Code and Students Exam Code will not working.

Thank You

0 likes
1 reply

Please or to participate in this conversation.