jcadima
3/21/2018 - 4:43 PM

Paginate on a hasMany collection


https://laracasts.com/discuss/channels/laravel/how-to-paginate-eloquent-hasmany-relation

User::find(122)->sites->paginate() ;  // will not work because it is trying to access
              a method of site property
User::find(122)->sites()->paginate();  // works, needs to be to be enclosed in parenthesis


$user_history = User::find( Auth::id() )->uservideos->paginate(20);  //Will not work
$user_history = User::find( Auth::id() )->uservideos()->paginate(20); // OK