mardi 31 mars 2020

Laravel user roles ,Multi auth

I', trying to differentiate the user based on perspective role, i.e Admin, Supervisor, student etc. When admin or supervisor login it must go to their specific dashboard, and each user must not access other user's roles when one try access via ** URL * Im trying to do this using a single table USER adding additional field Role as type integer Below is my code for all related files.

Admin and Supervisor Middle ware code is same

namespace App\Http\Middleware;

use Closure;

class Admin { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (! Auth::check()) { return redirect()->route('login'); }

if (Auth::user()->role == 1) {
    return redirect()->route('admin');
}
if (Auth::user()->role == 2) {
    return redirect()->route('supervisor');
}

}

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire