Have a unique ID for each answer.
Find out which page has a specific record in pagination?
I'm working on a "forum like" app and when viewing a thread, a user can also choose to view a post in a thread (an specific one).
The URL can be something like /thread/29?post=22. Now, a thread can have many posts. Therefore, since it's paginated with 10 posts per page, a post can be in any page depending on when it was posted.
I have no way of knowing which page the post is on in the record.
My code:
$posts = Post::where('thread_id', $thread->id)->paginate(10);
//there are over 50+ posts for instance
My simplified view:
@foreach ($posts as $post)
<span id="post{{ $post->id }}">Post #{{ $post->id }}</span>
{{ $post->body }}
@endforeach
My example URL would look like: http://example.com/thread/1
How would I know which page has a specific record? Say I want to go to the post with ID 28 which belongs to thread with an ID 1. How would I know which page of the result that thread is in?
I want to do something like:
http://example.com/thread/1?post=28&page=2 //authomatically guessed that post 28 would be in page 2.
how can do do this? Thanks!
Please or to participate in this conversation.