我收到了我的laravel(7.x)應(yīng)用程序。我必須用hasMany
關(guān)系來建模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
來計(jì)算total number of pages
。
我已經(jīng)嘗試過這個(gè)auth()->user()->withCount('referrals')
,但是沒有用。
嘗試在末尾添加
->get();
。