⚝
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
/
hospital.dev-unit.com
/
app
/
Models
/
View File Name :
Department.php
<?php namespace App\Models; use Eloquent as Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Spatie\Permission\Contracts\Role as RoleContract; use Spatie\Permission\Exceptions\RoleDoesNotExist; use Spatie\Permission\Guard; use Spatie\Permission\Traits\HasPermissions; /** * Class Department * * @version February 12, 2020, 5:39 am UTC * * @property string name * @property bool is_active * @property int $id * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $deleted_at * * @method static bool|null forceDelete() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department newQuery() * @method static \Illuminate\Database\Query\Builder|\App\Models\Department onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department query() * @method static bool|null restore() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department whereIsActive($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Department whereUpdatedAt($value) * @method static \Illuminate\Database\Query\Builder|\App\Models\Department withTrashed() * @method static \Illuminate\Database\Query\Builder|\App\Models\Department withoutTrashed() * * @mixin \Eloquent * * @property string|null $guard_name * @property int $is_default * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Permission\Models\Permission[] $permissions * @property-read int|null $permissions_count * * @method static Builder|Department permission($permissions) * @method static Builder|Department whereGuardName($value) * @method static Builder|Department whereIsDefault($value) */ class Department extends Model implements RoleContract { use HasPermissions; public $table = 'departments'; const INACTIVE = 0; const ACTIVE = 1; const ACTIVE_ALL = 2; const ACTIVE_ARR = [ self::ACTIVE_ALL => 'All', self::ACTIVE => 'Active', self::INACTIVE => 'Deactive', ]; const ROLE = [ 0 => 'All', 1 => 'Admin', 2 => 'Doctor', 3 => 'Patient', 4 => 'Nurse', 5 => 'Receptionist', 6 => 'Pharmacist', 7 => 'Accountant', 8 => 'Case Manager', 9 => 'Lab Technician', ]; public static function boot() { parent::boot(); self::creating(function (self $department) { $department->guard_name = 'web'; }); } public $fillable = [ 'name', 'guard_name', 'is_active', ]; protected $hidden = ['created_at', 'updated_at']; /** * Get the attributes that should be cast. * * @return array<string, string> */ protected function casts(): array { return [ 'id' => 'integer', 'is_active' => 'boolean', ]; } /** * Validation rules * * @var array */ public static $rules = [ 'name' => 'required|string', ]; /** * 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'), 'role_id', 'permission_id' ); } /** * A role 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_roles'), 'role_id', config('permission.column_names.model_morph_key') ); } /** * @return RoleContract|Builder */ public static function findByName(string $name, $guardName = null): RoleContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $role = static::where('name', $name)->where('guard_name', $guardName)->first(); if (! $role) { throw RoleDoesNotExist::named($name); } return $role; } /** * @return RoleContract|Builder */ public static function findById(string|int $id, ?string $guardName = null): RoleContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $role = static::where('id', $id)->where('guard_name', $guardName)->first(); if (! $role) { throw RoleDoesNotExist::withId($id); } return $role; } /** * Find or create role by its name (and optionally guardName). * * @return RoleContract|Builder */ public static function findOrCreate(string $name, $guardName = null): RoleContract { $guardName = $guardName ?? Guard::getDefaultName(static::class); $role = static::where('name', $name)->where('guard_name', $guardName)->first(); if ($role) { return $role; } return static::query()->create(['name' => $name, 'guard_name' => $guardName]); } }