[Vuejs]-How do I fetch comments with Laravel Pagination that are not redundant?

0๐Ÿ‘

โœ…

My thanks to @James. Iโ€™m saving the last ID of all fetched Comments + using a WHERE Query

I changed the Vue Method to:

url() {
    this.page++;
    return `${location.pathname}/comments?page=${this.page}&lastComment=${this.idOfLastComment}`;
},

And in my Controller:

/**
 * Fetch all relevant comments.
 *
 * @param string $username
 * @param Selllink $selllink
 */
public function index($username, $selllink)
{
    $commentID = request('lastComment', $default = 0);
    $filter = $commentID == 0 ? '>' : '<=';

    return $selllink->sell->comments()
                ->where('id', $filter, $commentID)
                ->latest()
                ->paginate(10);
}

Works perfectly ๐Ÿ™‚

Leave a comment