订阅模型:用户与用户的关系

I have a model Subscribe. Migration looks like this:

Schema::create('subscribes', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->integer('channel_id');
    $table->integer('user_id');
    $table->timestamps();
});

The defined relationships are:

class User
{
    public function subscribes()
    {
        return $this->hasMany('App\Subscribe', 'channel_id', 'id');
    }
}

class Subscribe
{
    public function user()
    {
        return $this->belongsTo('App\User');
    }
}

How can I display all subscribed users for another user?

So what you really want is two relationships on each model, one for subscriptions and one for followers. You can also add additional functions to retrieve subscriptions and followers:

class User
{
    public function subscriptions()
    {
        return $this->hasMany(Subscribe::class, 'user_id', 'id');
    }

    public function followers()
    {
        return $this->hasMany(Subscribe::class, 'channel_id', 'id');
    }

    public function getFollowedUsers()
    {
        return User::query()
            ->whereHas('followers.subscribingUser', function ($query) {
                $query->where('id', $this->id);
            })
            ->get();
    }

    public function getFollowingUsers()
    {
        return User::query()
            ->whereHas('subscriptions.followedUser', function ($query) {
                $query->where('id', $this->id);
            })
            ->get();
    }
}

class Subscribe
{
    public function subscribingUser()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function followedUser()
    {
        return $this->belongsTo(User::class, 'channel_id', 'id');
    }
}

Note: I changed subscribes to subscriptions because that's the correct wording.

With these relationships and methods, displaying both, subscribed and followed users, is extremely simple:

$user = User::find(1);

$subscriptions = $user->getFollowedUsers();
$followers     = $user->getFollowingUsers();