Skip to content

Commit

Permalink
fix: Cast BanTypeEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
CalumTowers committed Nov 10, 2023
1 parent c64046d commit 00c005a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions app/Models/Mship/Account/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @property int $id
* @property int $account_id
* @property int|null $banned_by
* @property int $type
* @property BanTypeEnum $type
* @property int|null $reason_id
* @property string $reason_extra
* @property \Carbon\Carbon|null $period_start
Expand Down Expand Up @@ -71,6 +71,7 @@ class Ban extends Model
'created_at' => 'datetime',
'repealed_at' => 'datetime',
'updated_at' => 'datetime',
'type' => BanTypeEnum::class,
];

protected $touches = ['account'];
Expand All @@ -79,12 +80,12 @@ class Ban extends Model

public static function scopeIsNetwork($query)
{
return $query->where('type', '=', BanTypeEnum::Network->value);
return $query->where('type', '=', BanTypeEnum::Network);
}

public static function scopeIsLocal($query)
{
return $query->where('type', '=', BanTypeEnum::Local->value);
return $query->where('type', '=', BanTypeEnum::Local);
}

public static function scopeIsActive($query)
Expand Down Expand Up @@ -170,17 +171,11 @@ public function getIsExpiredAttribute()

public function getTypeStringAttribute()
{
switch ($this->attributes['type']) {
case BanTypeEnum::Local->value:
return trans('mship.ban.type.local');
break;
case BanTypeEnum::Network->value:
return trans('mship.ban.type.network');
break;
default:
return trans('mship.ban.type.unknown');
break;
}
return match ($this->type) {
BanTypeEnum::Local => trans('mship.ban.type.local'),
BanTypeEnum::Network => trans('mship.ban.type.network'),
default => trans('mship.ban.type.unknown'),
};
}

public function getPeriodAmountStringAttribute()
Expand Down

0 comments on commit 00c005a

Please sign in to comment.