I am creating post-comment system where each post will have many comments. I want to fetch the comments of a specific post when click on 'comments' button alike facebook. I am using laravel 5.4 and Vue 2.0. I can fetch the comments of each post which now attaching to every post. I want to attach the child comments to its parent post. here my code:
<div class="post-section" v-for="post in posts">
<post>{{post.body}}</post>
<button @click="getComments(post)" class="btn btn-link">Comments</button>
<div class="comment" v-for='comment in comments'>
<p>
<span> {{comment.comment}}</span>
</p>
</div>
<script>
export default {
data() {
return {
posts: [],
comments: [],
}
},
created() {
Post.all(posts => this.posts = posts)
},
methods: {
getComments(post) {
axios.post('getcomments', {id: post.id}).then(response => {
console.log(response.data);
this.comments = response.data;
})
}
}
}
Thanks in advance for help !!