Laravel 11 Full Course 2025: CRUD in Laravel (delete) [Lesson #7]

Опубликовано: 17 Август 2026
на канале: codingoblin
243
4

In this video we are going to learn how to Delete models in Laravel. So we are focussing on the Delete part of CRUD in our Laravel web application.

Steps
The first thing we need to do is have a little tidy up of our existing course edit page. We want to place the form that is used to update the course into its own separate component named UpdateForm.vue. This makes it easier to see what is going on and helps us stay productive.

Now we can create a new component that will contain our frontend code to delete a course. This will be included in our /Courses/Edit/Index.vue beneath the UpdateForm.vue component that we just created. This component will take course as a prop as we will need the course id in order to delete it. We will make use of the ActionSection component provided by Laravel Jetstream, to structure the layout with title, description and content named slots. This is very similar to the FormSection component, just without the form. Within the content slot of this component we will have a modal that prompts the user to confirm that they want to delete the course before proceeding to do so. This is also very easy to do thanks to the pre-build ConfirmationModal component provided by Laravel Jetstream. The SectionBorder component allows us to divide our UpdateForm and DeleteForm sections nicely in out Index.vue.

Once we have the structure of our DeleteForm component sorted, we need to create a function to handle when the user clicks the button to delete their course. For this we will be making a manual visit using the router helper provided by inertia.js. So we will make a delete request to a 'courses.delete' route and pass the id of the course so we can access it via dependency injection. the id of the course can be accessed from the course prop passed to the component like this:
props.course.id

We now need to create the route to delete our course in the web.php file. This route needs to use the delete http method and take a course route param. We will also point it to a 'delete' method on the CourseController, which does not yet exist.

We can now create the delete() method in our CourseController to handle the deletion of our course. So head back to CourseController.php to do this. Our method must take Course so the course can be accessed via dependency injection. We then call the delete() method on the Course model that is accessed in the method.

You have now mastered the Delete part of CRUD in Laravel!

Table of contents
00:00 - Recap
00:30 - Tidy existing edit page with separate components
02:34 - Create delete course component
10:50 - Create function to delete course in component
12:20 - Create the route to delete course
12:50 - Create delete() method on CourseController
15:00 - A word on security