In this video, we are going to add comments to a post.
The hard work of the logic is done.
That is the API implementation.
So let's try to revisit and see the logic behind it.
First of all, we are going to find the post that we want to add the comment to.
Next is we go ahead and create and we push the comment into post and also we add the user into it and
finally we save it.
So the only requirement is the idea of the post that we need from the front end.
So for this one, we are not going to render a form because we have the form already been rendered inside
the post details page and lucky for us we also have the ID of the post, which is this one.
So we can go ahead and take this ID and make the HTTP request by passing in the message of the comment.
So let's go ahead and then finish up with that.
So let's get back to the post details inside the views, post and post details.
So let's go down and look for the comments.
And this is a form the action, meaning the path is going to be let's cross check again comments and
is going to be API version one and then the comment and then the ID of the post.
So let's see how we are going to implement that.
So let's get back to the post details and here is the comment form.
The action or the path goes like API version one.
Comments.
And then the ID of the post.
Which is equal to posts, and that's called ID for this one.
We are not going to use method override because our client site form support at HTTP method called post.
So we are lucky here as post it can be uppercase or lowercase.
The name here would be the message that holds the value of our comments.
If we cross check the model.
That is what we are accepting as the value of our comment as message.
So back here now, we are done with it, guys.
We are done with it.
So next step is let's make the HTTP request to test this endpoint to see if it's going to work.
Before we check it out, let's try to console.log what we have created inside the Command create controller
before sending the response, I would like to console.log the post.
I Is that, sir?
Moment of truth.
Let's refresh it.
And.
Let me add my message as excellent.
Submit.
And you can see that my message has been submitted successfully.
And if I check the terminal and you can see that this is a comment I just created and it is inside the
comment array of the post so I can go ahead and then loop through the comments of this particular post
and display it accordingly.
So let's see if we are populating the comments.
So let's get back to the post details and let's have a look.
Let's get back to the post and post details.
Let's grow up for the post details.
Indeed we are.
What display the comments of the post details.
So let's go ahead and then display them accordingly.
So let's get back to the post details and this is where we are looping through the comment.
And this is a container.
If you collapse eight, we can see that this is a container for the comments.
And let's look at the number of comments that we have added so far.
We can see we have a class called comments, meaning this one represents a single comment.
So if I collapse eight the first comment second and that is it.
All right.
So the next video, let's go ahead and display all the comments that we have created.