/** * * Force the role to have the given permission. * * @param $permissionName */ public function forcePermission($permissionName) { // If the role has not been given a the said permission if (null == $this->perms()->where('name', $permissionName)->first()) { // Load the given permission and attach it to the role. $permToForce = Permission::where('name', $permissionName)->first(); $this->perms()->attach($permToForce->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; }