When user clicks on icon, ajax call to controller is called and controller returns some comments.
My controller
public function read($id)
{
$comments = Comment::where('post_id', $id)->get();
return response()->json([
'html' => view('includes.comments')->render(),
'comments' => $comments
]);
}
var comments_box = comments_container.find('.comments-box');
comments_box.html(data.html);
console.log(data);
@foreach($comments as $comment) some code @endforeach
you need to pass the variable to the view (if you want to use that variable in the blade file)
for example by saying
return view('includes.comments', ['comments' => $comments]);
that way the $comments variable will be available in the blade file and you can then use the @foreach
more on views documentation