mercredi 17 janvier 2018

Authentication for multiple role with only 1 users table and 1 roles table

Hi im currently having trouble with the laravel 5.5 authentication for multiple roles. Most answers and tutorials are using multiple table for each user type, but in my project i have a users table with ('email', 'password', 'role_id', 'user_fullname', 'birthday','sex', 'address', 'phone', 'user_status') columns and it connected to a roles table with ('role_id', 'title', 'role_permissions) columns , they both connected to each other through role_id. The role_id are from 1->4(1:super admin, 2: editor, 3:manager, 4:user) I got a back end(super admin, editor, manager) login with the default authentication as the main page login(role:user only). My CheckAdmin middlewares doesn't seem to work when i put all the backend views in the Route::group(['middleware'=>'admin']) Here my CheckAdmin middleware

class CheckAdmin
{
    public function handle($request, Closure $next)
    {
        if(Auth::user() && Auth::user()->role_id != 4){
            return $next($request);
        }
        return redirect('/backendlogin');
    }
}

and i still use the default for the backendlogin i tried to put it in the 'checkadmin' middleware but it doesn't seem to work Hope someone can help me :D



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mNy0SC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire