/** * get all permissions of user by roles having that user * */ private function get_permissions($roles) { $role_perm = new RolePermissions(); $roles_ids = array_keys($roles); $permissions = $role_perm->join('permissions', 'permissions.pid', '=', 'role_permissions.pid')->whereIn('rid', $roles_ids)->select('permissions.name', 'permissions.pid')->lists('name', 'pid')->toArray(); return $permissions; }
public function check_permission_access($permission_id, $user_roles) { $rolePermissionsCount = RolePermissions::where('pid', '=', $permission_id)->whereIn('rid', $user_roles)->count(); if ($rolePermissionsCount > 0) { return true; } return false; }
/** * This function used to save permission matrix */ public function savePermissionMatrix(Request $request) { access_check('manage_permission_matrix'); RolePermissions::truncate(); $permission_matrix = $request->input('pm'); if (count($permission_matrix) > 0) { foreach ($permission_matrix as $permission) { $piece = explode('_', $permission); RolePermissions::create(array('pid' => $piece[0], 'rid' => $piece[1])); } } Session::flash('success', 'Permission Matrix Saved successfully.'); return redirect('admin/permissionMatrix'); }
public function run() { \Focalworks\Users\RolePermissions::create(['rid' => 2, 'pid' => 2]); \Focalworks\Users\RolePermissions::create(['rid' => 3, 'pid' => 2]); }