Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

Obviously your comments needs to be on a separate table .. and one to many relationship will return the comments. just inserting the comment id as a hash to the comment link will do ?

0

I thinked same your idea. But when i deleted a comment or many comments of the post, that value have change.

0

astroanu said:

Obviously your comments needs to be on a separate table .. and one to many relationship will return the comments. just inserting the comment id as a hash to the comment link will do ?

This should work, because each comment will have a unique id. Something like:

?post_Id=thepostid&Id=thecommenttobookmark

Have to have info for both to bookmark. Something like this.

Last updated 9 years ago.
0

I made a function for this work. If you have any idea bester use function of Laravel, please tell me.

/*
 * Function count position of the comment in post
 * @param: $id [ID of comment]
 * @param: $arr [array id of all comment $post->comments()->lists('id')]
 * @return: number
 * */
function position_comment($id,$arr){
    $comments_per_page = 10;
    $pos = array_search($id,$arr);
    $pos = $pos+1;
    return ceil($pos/$comments_per_page);
}
0

See reply above, position don't matter, it can change, id won't. I am going to try your function later.

Last updated 9 years ago.
0

I am Vietnamese. And, I making a forum for Vietnamese Laraveler like this forum. In address

http://laraviet.net

I used $post->comments->lists('id') to ensure the order comments in view (templates) and don't query database

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.