Voyager: fix redirect based on user role

Created on 21 Feb 2017  路  8Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.4.12
  • Voyager Version: 0.11.1
  • PHP Version: 7.0.13
  • Database Driver & Version: mysql Ver 14.14 Distrib 5.7.17

Description:

After login procedure, if the user is non admin it takes user to site.dev/admin and nothing is displayed. instead of this my desired response is to navigate users to different dashboards based on the user role assigned

Steps To Reproduce:

After a fresh installation of laravel and voyager

  1. create new user and assign the role of normal user
  2. login using the newly created credentials

created a new route for dashboard /userdashboard for normal user
after login i want to redirect to /userdashboard if the user is a normal user

tried playing around with the routes for voyager but no success so far, i would like some assistance in figuring out exactly where and which route/file i need to edit, as i am unfamiliar with working on other packages customization on laravel.

also please note that i am new and trying to get the hang of it, any support is much appreciated.

stay awesome guys

Most helpful comment

No. You can give different access to each role you create, but your role MUST have browse_admin if you need to be able to log into Voyager's interface. So, you can create a new Role with only browse_admin and whatever else they need access to, and they won't be able to get to the other functionality (Database, Settings, Pages/Posts, Users, etc.)

All 8 comments

any solutions for this prob?

Hi there, I haven't been able to get any solutions yet, for now I choose to go with native multiauth using guards and middleware for my current project.

But would love to see a solution tho this as voyager was very convenient :)

What other roles are you intending to use? Voyager is intended to be an "admin" tool, so normal "front-end" users of your site shouldn't be accessing it for any reason. If you have multiple levels of "admin" users, then you can control that through the existing permissions with other roles, so long as that role has the browse_admin permission.

I'm not sure what part of your use-case isn't covered by this. Please explain further.

so, only superadmins can view the template?

No. You can give different access to each role you create, but your role MUST have browse_admin if you need to be able to log into Voyager's interface. So, you can create a new Role with only browse_admin and whatever else they need access to, and they won't be able to get to the other functionality (Database, Settings, Pages/Posts, Users, etc.)

Late Answer but for the record:
I used the VoyagerController
Like so

class VoyagerController extends Controller
{
public function index()
{

    if(Auth::user()->role_id == 1){
        return Voyager::view('voyager::index');
    }elseif(Auth::user()->role_id == 3){
        return Redirect::action('XXXXXXXController@index');
    }elseif(Auth::user()->role_id == 4){
        return Redirect::action('IssuerController@index');

    }else{

      return  view('voyager::XXXXXXX.cardholder');
    }


}

@Eishaden, again, very old issue and it's been closed for months. Adding comments at this point is not beneficial

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevinjon27 picture kevinjon27  路  3Comments

TXRRNT picture TXRRNT  路  3Comments

iwasherefirst2 picture iwasherefirst2  路  3Comments

duongsieu picture duongsieu  路  3Comments

winex01 picture winex01  路  3Comments