/** * * Force the user to have the given role. * * @param $roleName */ public function forceRole($roleName) { // If the user is not a member to the given role, if (null == $this->roles()->where('name', $roleName)->first()) { // Load the given role and attach it to the user. $roleToForce = Role::where('name', $roleName)->first(); $this->roles()->attach($roleToForce->id); } }
public static function ParseUpdateAuditLog($id) { $permsObj = []; $permsNoFound = []; $rolesObj = []; $rolesNotFound = []; $audit = \Etherbase\App\Models\Audit::find($id); $dataAtt = json_decode($audit->data, true); // Lookup and load the perms that we can still find, otherwise add to an separate array. if ($dataAtt['perms']) { foreach ($dataAtt['perms'] as $id) { $perm = \Etherbase\App\Models\Permission::find($id); if ($perm) { $permsObj[] = $perm; } else { $permsNoFound[] = trans('admin/users/general.error.perm_not_found', ['id' => $id]); } } } $dataAtt['permsObj'] = $permsObj; $dataAtt['permsNotFound'] = $permsNoFound; // Lookup and load the roles that we can still find, otherwise add to an separate array. if ($dataAtt['selected_roles']) { $aRolesIDs = explode(",", $dataAtt['selected_roles']); foreach ($aRolesIDs as $id) { $role = \Etherbase\App\Models\Role::find($id); if ($role) { $rolesObj[] = $role; } else { $rolesNotFound[] = trans('admin/users/general.error.perm_not_found', ['id' => $id]); } } } $dataAtt['rolesObj'] = $rolesObj; $dataAtt['rolesNotFound'] = $rolesNotFound; // Add the file name of the partial (blade) that will render this data. $dataAtt['show_partial'] = 'admin/users/_audit_log_data_viewer_update'; return $dataAtt; }