feat: add reciprocal user blocking
CI / 🧪 Tests Laravel (push) Successful in 2m6s
CI / 🐳 Build & Push Image (push) Successful in 39s

This commit is contained in:
2026-08-11 15:58:31 +02:00
parent 6b757c37be
commit cef3e29ddc
15 changed files with 420 additions and 17 deletions
+29 -2
View File
@@ -12,9 +12,11 @@ use Filament\Models\Contracts\HasAvatar;
use Filament\Panel;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
@@ -152,20 +154,45 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
return $this->morphMany(Report::class, 'reportable');
}
public function followers(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
public function followers(): BelongsToMany
{
return $this->belongsToMany(self::class, 'follows', 'following_id', 'follower_id')
->withPivot('status')
->withTimestamps();
}
public function following(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
public function following(): BelongsToMany
{
return $this->belongsToMany(self::class, 'follows', 'follower_id', 'following_id')
->withPivot('status')
->withTimestamps();
}
public function blockedUsers(): BelongsToMany
{
return $this->belongsToMany(self::class, 'user_blocks', 'blocker_id', 'blocked_id')
->withTimestamps();
}
public function blockedByUsers(): BelongsToMany
{
return $this->belongsToMany(self::class, 'user_blocks', 'blocked_id', 'blocker_id')
->withTimestamps();
}
public function scopeWithoutBlockingRelationshipWith(Builder $query, User $user): Builder
{
return $query
->whereDoesntHave('blockedByUsers', fn (Builder $blockedByQuery): Builder => $blockedByQuery->whereKey($user->getKey()))
->whereDoesntHave('blockedUsers', fn (Builder $blockedQuery): Builder => $blockedQuery->whereKey($user->getKey()));
}
public function hasBlockingRelationshipWith(User $user): bool
{
return $this->blockedUsers()->whereKey($user->getKey())->exists()
|| $this->blockedByUsers()->whereKey($user->getKey())->exists();
}
public function moderationCase(): MorphOne
{
return $this->morphOne(ModerationCase::class, 'caseable');