Calling destroy method in resource controller
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Mastering Resource Controllers: How to Call the `destroy` Method in Laravel
As a senior developer, I frequently encounter confusion when working with RESTful APIs and resource controllers in Laravel. The process of deleting a resourceâcalling the `destroy` methodâoften seems straightforward, but the interaction between routes, HTTP verbs, and HTML forms can lead to subtle bugs.
The issue you are facing stems from understanding how Laravel maps incoming HTTP requests (like `GET`, `POST`, or `DELETE`) to the corresponding methods defined in your controller. This post will walk you through the exact mechanism of calling the `destroy` method correctly within a resource controller setup, addressing the confusion around form method spoofing.
## Understanding Resource Routes and RESTful Deletion
When you use `Route::resource('posts', 'PostController');`, Laravel automatically sets up seven standard CRUD routes for your `PostController`. Crucially, it defines a route specifically for deletion: `/posts/{post}/destroy`.
For this route to work correctly, the corresponding method in your controller *must* accept the ID of the item to be deleted as an argument. This is exactly what you have done with your `destroy($id)` method.
### The Controller Logic
Your provided `PostController` snippet demonstrates the correct implementation for deletion:
```php
public function destroy($id)
{
// 1. Find the record by ID
$post = posts::find($id);
// 2. Perform the deletion
if ($post) {
$post->delete();
}
// 3. Redirect after successful operation
return redirect('/');
}
```
This method correctly uses Eloquent to find the record based on the provided `$id` and then calls the `delete()` method, following best practices for data manipulation in Laravel.
## The Crucial Role of Form Method Spoofing (`@method`)
The confusion often arises when dealing with HTML forms. Standard HTML forms can only submit data using `GET` or `POST`. They do not natively support the `DELETE` verb required for true RESTful deletion. To trick the browser into sending a `DELETE` request, we use a meta-directive provided by Laravel: `@method`.
In your Blade file:
```html
```
This directive is essential because it instructs Laravel's routing system to interpret the incoming request not as a standard `POST` request, but specifically as a `DELETE` request aimed at the route defined by `route('posts.destroy', $post->id)`. Without this instruction, the route would only match the `POST` method, and your controller's `destroy($id)` function would never be executed when you submit the form.
## Step-by-Step Implementation Guide
To ensure your deletion works flawlessly, follow these steps:
### 1. Define the Route Correctly (Already Done)
Ensure your resource routes are set up correctly in `routes/web.php`:
```php
Route::resource('posts', 'PostController');
```
### 2. Implement the Controller Method
Make sure the method accepts the dynamic ID:
```php
public function destroy($id)
{
// ... deletion logic ...
}
```
### 3. Construct the Form in Blade
Use the `@method('DELETE')` directive within your form to signal the intent of the request:
```html
```
By ensuring that your route definition matches the resource structure, implementing robust logic in the controller, and correctly spoofing the HTTP method in the form, you successfully bridge the gap between standard HTML forms and Laravelâs powerful routing system. This level of detail is fundamental to building scalable applications with Laravel. For deeper dives into Eloquent relationships and model interactions, always refer to resources like https://laravelcompany.com.
## Conclusion
Calling the `destroy` method in a Laravel resource controller is not about finding a missing function; it's about coordinating three components: **Routes**, the **Controller Logic**, and the **View Submission**. The key takeaway is that while HTML forms are limited, the `@method('DELETE')` directive acts as the necessary instruction, allowing your form submission to correctly trigger the intended `destroy($id)` method. Mastering this interplay is a hallmark of effective Laravel development.