I'm having issues figuring out how to paginate a many to many relationship. I'm trying to get create a forum app similar to this one here. I attempted to paginate questions asked on a forum with specific tags eg. /discuss/tags/laravel
Question Model:
public function tags()
{
return $this->belongsToMany('App\Tag');
}
Tag Model:
public function questions()
{
return $this->belongsToMany('App\Question');
}
Controller:
public function tag($slug)
{
$tags = Tag::with('questions')->whereName($slug)->paginate(15);
return view('questions.channel', compact('tags'));
}
Template:
@foreach ($tags as $tag)
@foreach ($tag->questions as $question)
@endforeach
@endforeach
I can get the proper data to display on my blade template, however can't figure how I would ago about adding pagination to my template. I'm not getting any errors.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire