Okay guys, next up we need to define the routes for this posts controller.
So let me start by copy pasting the same fragment a couple of times.
So let's make it this way.
So we only have to fill out the action and the last part of the route.
So this one would be for listing every single post, then a form for creating the post, then the form
submission.
That would be a post, then the edit form.
So that's get.
Then we've got the edit form submission and finally deleting of a post.
Now in frameworks like Laravel, since if you stick to conventions of naming your controller actions,
then it would be much simpler.
You can use something like router resource and it will automatically assume some default routes and
some default controller actions, which is super handy, and we might think about that later on.
For now, we need to do some manual labor.
So this first action is index.
The second one is create.
And also we need to change the route a little.
Next up it's post and the action is store.
Then we display the edit form.
This needs an ID parameter.
And that's the part of the path called edit.
And the action it can also be called edit.
Now the submission of this form.
This just needs ID in the path.
And the the name of the method is update.
And finally to delete a post we can do it.
This way.
Normally we can just use a delete verb, but it's hard to submit a form with delete method.
That's why we're going to add this specific path.
And we're going to call the delete method.
I think we've got every single route defined.
Next up we should add a view to display those posts.
So inside the views folder dashboard.
Or maybe we should create another one.
So this is posts or rather posts.
Let's stick to this convention.
Let me call that post.
And let's begin by creating an index.php file.
And in here we can say manage posts.
Let me see if this works right away.
Um well it should work.
So let me jump to the post admin controller and let me see why this doesn't work.
Okay, so we've assumed that the template name starts with posts, and it seems that we used the post
convention before.
So let me stick to it.
And I think that's the only one.
Okay.
Now we have this page.
So let me go back to it.
Manage posts.
We should have a link here that would be called create a New post.
This is Create New.
Post and it's going to lead to admin post create.
Well template doesn't exist so that was expected.
And now let's just use a table.
I think it might suit our situation well.
Let me add a head section on the table and one row.
And now sorry that's not TD.
It is th.
In the table header we're going to have a title.
Then another one would be when a post was created.
And then finally we're going to have some actions to do.
Okay.
So it looks like this.
And then after the t head section let's add a T body.
Now this is where we're going to display all the posts.
That's why we're going to use for each posts as post.
And I'm going to close this with and for each inside every single one we display a row and the values.
So we're going to use HTML special chars as usual to display the post title.
The next column will just display the post created.
At date.
And the last one.
This would be actions.
So we've got a couple of those actions in here.
Let me move to another row.
So the one is to edit this would be admin posts post ID slash edit.
And this can be just a link.
But then the next action is more destructive.
It's deleting a post.
That's why we need a form for that.
And the action here.
This is admin posts Again, we need the post ID and then it is delete and the method here is post.
And inside we just need a button that will say delete.
The type of it is submit.
And we might add a tiny bit of JavaScript in here.
Just a simple confirmation.
So we're going to do return confirm.
And we're going to ask the user if he really wants to delete a post by asking are you sure.
Okay.
So maybe let's do a quick test.
Let's try to delete one of those blog posts, maybe this one.
So we are being asked if we really want to do that.
If I say cancel, well nothing happened.
I have refreshed the page and the blog post is still there.
But if I go ahead with okay, um, well, we've got an expired page.
So as you see, the protection by default works fine.
That's why we need the CSRF token.
And now let me try again.
Let me try to remove this post.
And there we have it.
One of our free posts was just removed and it's gone forever.
So this worked fine now.
Well we are missing the templates for editing, so next up we should be adding them.
But for now we've got the list of posts.
We've got the delete button working, and we need to still work on adding the post and editing, which
I think we can do next in the next videos.