Witajcie.

Mam taki kod:

  1. class ForumCategory extends Model
  2. {
  3. use scopeActiveTrait;
  4.  
  5. protected $quarded = ['id'];
  6. protected $fillable = ['company_id', 'enable', 'name', 'url_address', 'enable'];
  7. public $timestamps = false;
  8.  
  9. public function themes()
  10. {
  11. return $this->hasMany('App\ForumPost', 'id_category', 'id')->where('parent_id', '=', null);
  12. }
  13.  
  14. public function lastPost()
  15. {
  16. return $this->themes()->orderBy('id', 'desc')->first();
  17. }
  18. }
  19.  
  20. class ForumPost extends Model
  21. {
  22. use scopeActiveTrait;
  23.  
  24. protected $quarded = ['id'];
  25. protected $fillable = ['company_id', 'id_category', 'parent_id', 'user_id', 'date', 'title', 'content', 'url_address', 'enable'];
  26. public $timestamps = true;
  27. protected $table = 'forum';
  28.  
  29. public function category()
  30. {
  31. return $this->belongsTo('App\ForumCategory', 'id_category');
  32. }
  33.  
  34. public function author()
  35. {
  36. return $this->belongsTo('App\User', 'user_id');
  37. }
  38.  
  39. public function postCount()
  40. {
  41. return $this->hasMany('App\ForumPost', 'parent_id', 'id')->where('parent_id', '!=', null)->count();
  42. }
  43. }



Po wywołaniu funkcji:

  1. ForumCategory::with('themes')->orderBy('name', 'asc')->paginate(35);



Mam paginację dla kategorii.


W momencie gdy wyświetlam wyniki tej funkcji:

  1. @foreach ($forums as $forum)
  2. Welcome in {{ $forum->name }}<br/>
  3. @foreach ($forum->themes as $post)
  4. Post: {{ $post->title }}
  5. @endforeach
  6. <div class="paginationFormat"></div>
  7. <div class="text-right">{{ $forums->links() }}</div>
  8. @endforeach



Mogę wyświetlić paginację dla $forums.

Chciałbym dodatkowo wyświetlić paginację dla $post (danych z relacji). W jaki sposób można to zrobić?