Anyone have any suggestions? Is there a method in pagination that might be able to handle this?
Find the pagination page where an item will be placed or exists
Hi everyone,
I am making a forum very similar to this one (it's my inspiration). When a user posts a reply to a thread I'd like to direct them to the end of the list of paginated replies with their reply's anchor (same behavior as this forum). I'd also like to return the user to the correct page when they edit one of their replies.
How can I figure out which page a new reply will be posted on (?page=x) and how can I return to the correct page after a reply has been edited? Or, from the main post listing, which page the latest reply is on?
Here is my current ForumPost model (minus a few unrelated things) -
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* Class ForumPost
*
* Forum Posts table
*
* @package App
*/
class ForumPost extends Model {
/**
* Post has many Replies
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function replies()
{
return $this->hasMany('App\ForumReply');
}
/**
* Get the latest reply for a post
* @return null
*/
public function latestReply()
{
$reply = $this->replies()->orderBy('created_at', 'desc')->first();
if ($reply) {
return $reply;
} else {
return null;
}
}
}
@JeffreyWay I know that you build this forum on your own, any tips? I'm not looking to distribute this code, just using it for a client.
Thanks!
Please or to participate in this conversation.