Threaded Comments, php, laravel -
this table newtheme_comment:
id parent_id id_theme user text upvotes downvotes
and controller:
class comments extends controller { public function generatecomments($id){ $comments = newtheme_comment::where('id_theme', $id)->paginate(5); return view('comments', ['comments'=>$comments]); }
id link general post(each posts have different section of comments), dynamically @ click of user, user redirected ('comments view') section of comments accordingly.
so have array comments populated values table newtheme_comment, problem me consists of how can use values create threaded comments section.
like in view(the problem makes comment section every parent_id equal 0 not looking for:
@foreach ($comments $comment) {{-- comments threads --}} <div class="media"> <div class="media-left"> </div> <div class="media-body"> <p class="media-heading">{{ $comment->text }}</p> <p class="media-heading">{{ $comment->user }} / {{ $comment->created_at }} </p> </div> </div> @endforeach {{-- comments threads --}}
the end result:
0 1 2 3 2 1 1 0 1 0
my idea make comments like(with parent_id):
0 1 2 3 2 1 1 0 1 0
but can't find right way thing logically, in end simple threaded comment section same reddit uses( little web application ).
if approach bad, appreciate other better ways on how solve this.
list every comment doesn't have parent_id, when load comments check if of comments have childs comments , list indentation.
Comments
Post a Comment