How to Paginate Eloquent hasMany relation?

Posted 3 years ago by stephen.talari

i have 'user' and 'sites' table with hasMany relation

User Model looks as

public function sites() {
        return $this->hasMany(Sites::class, 'user_id', 'id');

Sites Model looks as

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

In my controller, i tried to get all sites of a user and it works fine.


Now, how can i make this paginate ?

User::find(122)->sites->paginate() is failing.

Please sign in or create an account to participate in this conversation.