Laravel: withCount auth()->user() 关系

Laravel: withCount auth()->user() relationship

我是 laravel (7.x) 应用程序。我必须使用 hasMany 关系对 UserUserReferral 进行建模。

User.php

class User extends Authenticate implements MustVerifyEmail
{
    public function referrals()
    {
        return $this
            ->hasMany(UserReferral::class)
            ->orderBy('created_at', 'DESC')
            ->skip(0)
            ->take(10);
    }
}

UserReferral.php

class UserReferral extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}

Referrals 的列表有 load-more 个分页,total number of recordsnumber of pages

我需要获取 total number of records 来计算 total number of pages

我已经试过了 auth()->user()->withCount('referrals') 但它不起作用。

I have already tried this auth()->user()->withCount('referrals') but it doesn't work.

尝试在末尾添加->get();