Skip to content

Commit f11fabd

Browse files
committed
better level support
1 parent 2801501 commit f11fabd

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/Models/Concerns/Bannable.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function ban(
7777

7878
$this->bans->push($ban);
7979

80-
$this->ban_level = $ban->isActive();
80+
$this->ban_level = $ban->isActive() ? $ban->level : null;
8181
$this->save();
8282

8383
return $ban;
@@ -96,23 +96,35 @@ public function unban(): static
9696
return $this;
9797
}
9898

99-
public function isBanned(): bool
99+
public function isBanned(?int $level = null): bool
100100
{
101+
if ($level) {
102+
return $this->ban_level === $level;
103+
}
104+
101105
return $this->ban_level !== null;
102106
}
103107

104-
public function isNotBanned(): bool
108+
public function isNotBanned(?int $level = null): bool
105109
{
106-
return ! $this->isBanned();
110+
return ! $this->isBanned($level);
107111
}
108112

109-
public function scopeBanned(Builder $query): Builder
113+
public function scopeBanned(Builder $query, ?int $level = null): Builder
110114
{
115+
if ($level) {
116+
return $query->where('ban_level', '=', $level);
117+
}
118+
111119
return $query->where('ban_level', '!=', null);
112120
}
113121

114-
public function scopeNotBanned(Builder $query): Builder
122+
public function scopeNotBanned(Builder $query, ?int $level = null): Builder
115123
{
124+
if ($level) {
125+
return $query->where('ban_level', '!=', $level);
126+
}
127+
116128
return $query->where('ban_level', '=', null);
117129
}
118130
}

src/Models/Contracts/BannableContract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function ban(
3737
?array $metadata = null
3838
): Ban;
3939

40-
public function isBanned(): bool;
40+
public function isBanned(?int $level = null): bool;
4141

42-
public function isNotBanned(): bool;
42+
public function isNotBanned(?int $level = null): bool;
4343
}

0 commit comments

Comments
 (0)