Forum probably more of a one to many, a post has many answers. A user can only edit their post, ah but a different linkage to handle that, probably comes from auth. In real enterprise, several one to many's is better than the mess many to many can create. Just my opinion.
Oct 1, 2016
2
Level 3
Pagination with many to many
Hello,
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.user')->whereName($slug)->paginate(15);
return view('questions.channel', compact('tags',));
}
Template:
@foreach ($tags as $tag)
@foreach ($tag->questions as $question)
{{$question->title }}
{{$question->body }}
@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 have tried a few ways but all with errors.
Please or to participate in this conversation.