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

Deekshith's avatar

Giving shared access in admin dashboard

Hello, I have a admin dashboard and there are three roles,

user
admin
manager

User will have access to his dashboard and admin will have complete access to admin dashboard to mange the website.

i have a tables like below,

roles

id, name

role_permissions

id,role_id,can_access_admin,can_access_journal

in users table,

id, default_role_id,name,email

User.php

 public function role()
    {

        return $this->belongsTo('App\Models\Role', 'role_id', 'id');
    }

Role.php

public function permission()
    {
        return $this->hasOne('App\Models\RolePermission');
    }

RolePermission.php

public function role()
    {
        return $this->belongsTo('App\Models\Role', 'role_id', 'id');
    }

So now in controller to check if user logged in or not i have added below middleware,

public function __construct()
    {
      $this->middleware('auth');
    }

So now i have created a new middleware to check user can access admin panel like below,

public function handle(Request $request, Closure $next)
    {

        if (Auth::user()->role->permission->can_access_admin_panel)
            return $next($request);

       abort(401, 'This action is unauthorized.');
    }

and added this middleware in controller like below,

public function __construct()
    {
      $this->middleware('auth');
	$this->middleware('canAccessAdminPanel');
    }

this is working fine for user and admin.

Now i am trying to create a new role in admin end for manager role. and manger role will have access to only one module in admin end,

i have another column in role_permission table like, "can_access_journal" this coulmn can be used to check this user has access to that module or not.

But i want to redirect to same admin dashboard for the manager role too. but i want to restrict all other pages access and it should return unauthorized. So now manger should login to admin end and can access Journal management module and restrict other module access by returning unauthorized access. Any suggestions?

0 likes
1 reply
Kessler441's avatar

Navigate to Performance Analytics > Dashboard Admin.

Click a dashboard to open it.

Choose from the following options in the Visible to field: Everyone: Select roles that can access this dashboard.

Users and Groups: Select users and groups that can access the dashboard.

Also note that, users must have the pa_viewer role to view dashboards. Users with the pa_admin and pa_power_user roles can create and edit dashboards.

https://www.dgcustomerfirst.org/

Please or to participate in this conversation.