Laravel 8 E-Commerce - Admin Delete Category
In this video, we will learn about how to delete a category.
Let's see how we can delete a category. First, go to the AdminCategoryComponent.php Class File and create a method for deleting the category:
public function deleteCategory($id)
{
$category = Category::find($id);
$category->delete();
session()->flash('message','Category has been deleted successfully!');
}
Next, open the admin-category-component.blade.php view file and create a link for deleting the category:
<a href="#" wire:click.prevent="deleteCategory({{$category->id}})"><i class="fa fa-times fa-2x text-danger" style="margin-left:10px;"></i></a>
Save this file and let's check it. Switch to the browser and refresh the page.
Click on the delete link, and you will see that the category has been deleted successfully.
So, in this way, you can delete a category. That's all about deleting a category.