Hey, did everyone that they share and in this video we are going to work through that how admin can
delete a product or delete product is really, really simple.
Shouldn't be a much bigger of a deal.
So let's go ahead and copy this and there we go.
Now we got all of this.
Let's go ahead and minimize this one and we'll be working with the bottom one.
There we go.
So first thing is, we need to update that, which is admin delete one product, obviously one.
So we're going to hold the product just by the same logic we did in the last video.
So product is going to be requested params not ID.
If we are not able to find the product then this is an issue.
So this needs to be go up there.
We don't need to hold the reference of the array itself.
So we're going to go ahead and let's expand how we are handling the files now for the handling of the
file part, I would say that rather requesting the file itself, let's go ahead and cut out this logic
where we destroy the files.
So let's go ahead and cut this out and place it outside.
Because if we have found the product, then we would like to delete them.
So product photos, dot length and let's go ahead and destroy all of them.
Just deleting the model.
It is not good because we are placing the file somewhere else, so let's go ahead and remove that.
We don't need to hold the reference.
We can actually remove this entire part of the code and that's it.
That should also be fine.
We are not uploading any photos, so this shouldn't be needed.
So this should all this all can go away.
We are not checking for the files inside the body so that can also go away and this looks okay so far.
So we have found the product, we have removed the images.
We don't need to update anything from this area or something.
We just need to run a method to remove that.
So this should all the good.
Let's go ahead and work on with that.
Now removing is really, really simple.
All you got to do is simply say, hey, product and remember we are holding now.
We are not running this query directly on the product model itself, but the object that we have received
from this model.
So we're going to go ahead and say, hey, we want to just remove.
And that's pretty much it.
Since this is a database operation, we are going to go ahead and wait.
Maybe you want to hold the result into a response or available.
That's up to you.
But we are going to go ahead and just do that.
And we don't need to run this query, obviously, so we can go ahead and remove this status.
Success is true, and we're going to go ahead and send a simple message that product was deleted.
So product product was deleted with an exclamation.
There we go.
And that's all we'll be sending up.
Maybe you want to send what was the product being removed?
Do you want to send that?
That's up to you, but I don't think it's necessary.
So there we go.
Let's go ahead and bring this throughout and just update the previous route which we got.
So let's go ahead at that top.
There we go.
And housecleaning, purpose, extra comma.
Okay, let's see.
In the last route, we are having an admin product and ID.
We were updating that.
So this is a small bug.
It should be put.
I'm pretty sure you might have already noticed that.
And we need to change it on another method which is going to be simply dot not there.
There we go and dot delete.
There we go.
Dot delete.
And in the deletion case also will be following the same routine that user should be logged in.
He should be admin.
So custom role.
The role should be admin obviously.
And then we can actually add this one for the deleting of the product.
So the same route, wherever you are sending me the ID, if you send me a port request, I'll update
it.
If you send me a delete request, I'll delete that.
Looks great.
Looks fantastic, actually.
So there we go.
We have all the admin routes and in fact, at this point we can go ahead and put up a comment so we
can say these are admin admin only controllers and these are basic regular user controller.
So there we go.
We can actually minimise this one.
There we go.
Looks fantastic.
Absolutely clean code and absolutely readable code.
So that's it for this one.
Let's go in and catch up in the next one.