我收到了我的laravel(7.x)應用程序。我必須用hasMany
關系來建模User
和UserReferral
。
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 records
和number of pages
。
我需要得到total number of records
來計算total number of pages
。
我已經嘗試過這個auth()->user()->withCount('referrals')
,但是沒有用。
嘗試在末尾添加
->get();
。