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

afrasiyabhaider's avatar

How should i don't Show login form of teacher if already logged in as student?

I am using the multi-auth system and I am facing the problem. If I logged in as a student and I type route of teacher login form my application takes me there. Please tell me

How should I don't Show login form of the teacher if already logged in as a student

0 likes
8 replies
Tray2's avatar

You can do that with a custom middleware something like

<?php

namespace App\Http\Middleware;

use Closure;

class CheckUser
{
    public function handle($request, Closure $next)
    {
        if (Auth::user()->type == 'student') {
            return redirect('/');
        }

        return $next($request);
    }
}
Cronix's avatar

I am using the multi-auth system

Depends on what you mean by that and how you implemented it. This won't be an issue if you use a single auth system and just assigned roles to the users. You could then check the role in route middleware and only allow people with role of student to access some routes, and people with role of teacher to access others. Something like this in the docs: https://laravel.com/docs/5.8/middleware#middleware-parameters

jlrdw's avatar

it didn't worked

Perhaps double check your code because a single Authentication system works great for me, when the proper authorization is implemented.

And if I teacher can also be a student you may need to look into query Scopes as well.

And I hope I understand the question.

In my case I don't have student and teachers but I have admins and bookkeepers, where some are just admin, but one lady is an admin and a bookkeeper.

Have you viewed Jefferies free videos one on Authentication and he has another on basic authorization.

These are in his free from scratch series.

afrasiyabhaider's avatar
Level 2

I write these lines into all of my login controllers (student, teacher, staff)

    $this->middleware('guest:staff')->except('logout');
    $this->middleware('guest:student')->except('logout');
    $this->middleware('guest:teacher')->except('logout');
Cronix's avatar

That's exactly what I suggested.

jlrdw's avatar

Am I wrong or can a student in this system see other students data or have you already implemented proper authorization and Scopes as well.

Sorry just curious after seeing the solution.

Please or to participate in this conversation.