This commit is contained in:
2026-05-28 20:37:53 +02:00
parent 548100af74
commit 1db50bc69a
18 changed files with 253 additions and 11 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use App\Enums\FollowStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Follow extends Model
{
protected $fillable = [
'following_id',
'follower_id',
'status',
];
protected function casts(): array
{
return [
'status' => FollowStatus::class,
];
}
public function follower(): BelongsTo
{
return $this->belongsTo(User::class, 'follower_id');
}
public function following(): BelongsTo
{
return $this->belongsTo(User::class, 'following_id');
}
}
+14
View File
@@ -149,6 +149,20 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
return $this->morphMany(Report::class, 'reportable');
}
public function followers(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(self::class, 'follows', 'following_id', 'follower_id')
->withPivot('status')
->withTimestamps();
}
public function following(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(self::class, 'follows', 'follower_id', 'following_id')
->withPivot('status')
->withTimestamps();
}
public function moderationCase(): MorphOne
{
return $this->morphOne(ModerationCase::class, 'caseable');