Skip to content

Commit bd51e62

Browse files
committed
add latestBan
1 parent 4f76819 commit bd51e62

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Models/Concerns/Bannable.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Database\Eloquent\Builder;
1010
use Illuminate\Database\Eloquent\Collection;
1111
use Illuminate\Database\Eloquent\Relations\MorphMany;
12+
use Illuminate\Database\Eloquent\Relations\MorphOne;
1213
use Illuminate\Foundation\Auth\User;
1314
use Illuminate\Support\Facades\Auth;
1415

@@ -36,6 +37,14 @@ public function bans(): MorphMany
3637
return $this->morphMany(static::getModelBan(), 'bannable');
3738
}
3839

40+
/**
41+
* @return MorphOne<TBan, $this>
42+
*/
43+
public function latestBan(): MorphOne
44+
{
45+
return $this->morphOne(static::getModelBan(), 'bannable')->latestOfMany();
46+
}
47+
3948
/**
4049
* @param null|array<array-key, mixed> $metadata
4150
* @return TBan

src/Models/Contracts/BannableContract.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Database\Eloquent\Collection;
1010
use Illuminate\Database\Eloquent\Model;
1111
use Illuminate\Database\Eloquent\Relations\MorphMany;
12+
use Illuminate\Database\Eloquent\Relations\MorphOne;
1213
use Illuminate\Foundation\Auth\User;
1314

1415
/**
@@ -24,6 +25,11 @@ interface BannableContract
2425
*/
2526
public function bans(): MorphMany;
2627

28+
/**
29+
* @return MorphOne<TBan, Model>
30+
*/
31+
public function latestBan(): MorphOne;
32+
2733
/**
2834
* @param null|array<array-key, mixed> $metadata
2935
* @return TBan

0 commit comments

Comments
 (0)