samedi 28 avril 2018

How to restrict users after login

How can i restrict different users after they login so they wont access directories that they are not supposed to? That means everybody should access only their directories here is my login controller

protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();
        $this->clearLoginAttempts($request);

        foreach ($this->guard()->user()->roles as $role) {
            if ($role->name=='Admin') {
                return redirect('issuer');
            }else if ($role->name=='Approver') {
                return redirect('approver');
            }else if ($role->name=='Issuer')
            {
                return redirect('issuer');
            }else if ($role->name=='Requester')
            {
                return redirect('requester');
            }
        }
    }
    public function logout()
    {
        Auth::logout();
        Session::flush();
        return redirect('login');
    }

here is my user Model

protected $fillable = [
        'name', 'email', 'password','active',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];
    public function roles()
    {
        return $this->belongsToMany(Role::class,'role_users');
    }

Here is my Role Model

 protected $fillable = ['name'];

    protected $primaryKey = 'id';

    public function users()
    {
        return $this->belongsToMany(User::class, 'role_users');
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire