follow
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user