⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
crm.dev-unit.com
/
app
/
Models
/
View File Name :
Permission.php
<?php namespace App\Models; use Barryvdh\LaravelIdeHelper\Eloquent; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; use Spatie\Permission\Contracts\Permission as PermissionContract; use Spatie\Permission\Exceptions\PermissionDoesNotExist; use Spatie\Permission\Guard; use Spatie\Permission\PermissionRegistrar; use Spatie\Permission\Traits\HasRoles; /** * App\Models\Permission * * @property int $id * @property string $name * @property string|null $display_name * @property string|null $description * @property string|null $type * @property string|null $guard_name * @property Carbon|null $created_at * @property Carbon|null $updated_at * * @method static Builder|Permission newModelQuery() * @method static Builder|Permission newQuery() * @method static Builder|Permission query() * @method static Builder|Permission whereCreatedAt($value) * @method static Builder|Permission whereDescription($value) * @method static Builder|Permission whereDisplayName($value) * @method static Builder|Permission whereId($value) * @method static Builder|Permission whereName($value) * @method static Builder|Permission whereType($value) * @method static Builder|Permission whereUpdatedAt($value) * @mixin Eloquent * * @property-read \Illuminate\Database\Eloquent\Collection|Role[] $roles */ class Permission extends Model implements PermissionContract { use HasRoles; /** * Validation rules * * @var array */ public static $rules = [ 'name' => 'required|unique:permissions,name', ]; /** * @var string */ protected $table = 'permissions'; /** * @var string[] */ protected $fillable = [ 'name', 'display_name', 'description', ]; /** * The attributes that should be casted to native types. * * @var array */ protected $casts = [ 'id' => 'integer', 'name' => 'string', 'display_name' => 'string', 'description' => 'string', ]; public static function boot() { parent::boot(); self::creating(function (self $role) { if (empty($role->guard_name)) { $role->guard_name = Guard::getDefaultName(static::class); } }); } /** * @return BelongsToMany */ public function roles(): BelongsToMany { return $this->belongsToMany( config('permission.models.role'), config('permission.table_names.role_has_permissions'), 'permission_id', 'role_id' ); } /** * A permission belongs to some users of the model associated with its guard. */ public function users(): MorphToMany { return $this->morphedByMany( getModelForGuard($this->attributes['guard_name']), 'model', config('permission.table_names.model_has_permissions'), 'permission_id', config('permission.column_names.model_morph_key') ); } /** * Find a permission by its name (and optionally guardName). * * @param string $name * @param string|null $guardName * @return PermissionContract * * @throws PermissionDoesNotExist */ public static function findByName(string $name, $guardName = null): PermissionContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $permission = static::getPermissions(['name' => $name, 'guard_name' => $guardName])->first(); if (! $permission) { throw PermissionDoesNotExist::create($name, $guardName); } return $permission; } /** * @param int $id * @param null|string $guardName * @return PermissionContract */ public static function findById(int $id, $guardName = null): PermissionContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $permission = static::getPermissions(['id' => $id, 'guard_name' => $guardName])->first(); if (! $permission) { throw PermissionDoesNotExist::withId($id); } return $permission; } /** * Find or create permission by its name (and optionally guardName). * * @param string $name * @param string|null $guardName * @return PermissionContract */ public static function findOrCreate(string $name, $guardName = null): PermissionContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $permission = static::getPermissions(['name' => $name, 'guard_name' => $guardName])->first(); if (! $permission) { return static::query()->create(['name' => $name, 'guard_name' => $guardName]); } return $permission; } /** * @param array $params * @return Collection */ protected static function getPermissions(array $params = []): Collection { return app(PermissionRegistrar::class)->getPermissions($params); } }