تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Adding Remove-All Feature0:00

There's honestly not much more work to do on the back end. There is one more bit of functionality that's missing. If you look at the sidebar, we have this delete button here. And instead of removing one item from the cart, it should remove the whole quantity. So basically delete the cart item from the cart. All right, let's give it a shot. This time, I will start with the web routes. So I'm going to duplicate this. But this one is going to be route delete. And

Creating Delete Route0:23

the web routes. So I'm going to duplicate this. But this one is going to be route delete. And instead of product, we want to delete the cart item. And here we don't want to remove one. But essentially, we want to remove all instances of a product in the cart. And so I think cards that remove all makes sense since we have cards that remove one and add one. Let's go in our cart controller to implement that remove all action, public function remove all. And remember, it receives

Wiring Delete Form0:49

controller to implement that remove all action, public function remove all. And remember, it receives a cart item. And here, really, we don't even need to hit a model method, we can directly delete that cart item, and then return back to the same page. That should work just fine. So let's try wire up our this will be in the cart active. So once again, we're going to wrap this in a form, the action is going to be route, cut that remove all. And we need to pass not a product, but a

the action is going to be route, cut that remove all. And we need to pass not a product, but a cart item, I believe it's called item. Yep, this is it. So let's move the closing form tag here. And we need to add a few more things, a method of post. And Escopilot knows the CSRF token and the delete method. So let's quickly add the type of submit to the button. When we submit this form, it's going to hit the cart removal route in Web.php, which is this one, which is going to hit the

Testing Cart Deletion1:54

it's going to hit the cart removal route in Web.php, which is this one, which is going to hit the remove all method on the cart controller, which is going to receive the cart item and delete it. Once again, I'm pretty confident that it's going to work straight away. Let's give it a shot. So I'm going to add a bunch of items to my cart and maybe increment the quantity. And let's try remove the pistachio backlava in three, two, one, boom, it's gone. Let's try to remove the

Wrap-Up and Next Steps2:21

remove the pistachio backlava in three, two, one, boom, it's gone. Let's try to remove the creme brulee here with a quantity of four. You can see I can increment, decre ment, and it's working. And we're going to delete that in three, two, one, boom, it's gone. All right, we've done some massive progress. Basically, everything that is left to do is the order confirmation model. And of course, check that the UI works and is compliant with the challenge instructions.

And of course, check that the UI works and is compliant with the challenge instructions. But I'm pretty happy with where we're at. The functionality works great. I can increment the quantity. I can decrement the quantity and I can remove all together. So this is the waffle. I can completely remove it. You can see now it's back to add to cart. Everything is working great. That is a great place to wrap up this lesson. I'll see you in the next one.

That is a great place to wrap up this lesson. I'll see you in the next one.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟