Add new methods to a resource controller in Laravel

Add new methods to a resource controller in Laravel

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Extending Laravel Resource Controllers Beyond CRUD Defaults

Laravel's resource controllers provide a convenient scaffold for standard Create, Read, Update, and Delete operations. By convention, they expose methods named index, create, store, edit, update, and destroy. However, this naming convention doesn't mean you are locked into a strict six-method limit. You can absolutely add additional methods to handle specific business logic or API endpoints that fall outside the standard RESTful cycle.

The primary mechanism for adding new routes is simply defining new methods within the controller class and then mapping them to your routes/web.php or routes/api.php file. There is no internal magic in Laravel that restricts a resource controller to only its default methods; the framework treats any public method as a potential route target, provided you define the corresponding entry point.

To add a new endpoint, start by defining a method inside your controller class. For example, if you need an endpoint to generate a PDF report for a specific resource, you might create a downloadReport method:

class ArticleController extends ResourceController
{
    // ... existing methods like index() and show()

    public function downloadReport($article)
    {
        $pdf = \Spatie\PDFGenerator\Facades\Pdf::loadView('articles.report', compact('article'));
        
        return $pdf->stream('report-' . $article->id . '.pdf');
    }
}

Once the method exists, you must explicitly register the route. In a standard application using routes/web.php, this looks like:

Route::get('/articles/{article}/report', [ArticleController::class, 'downloadReport']);

Alternatively, if you prefer to keep your resource controller methods consistent with REST verbs, you can use HTTP method-specific routes:

Route::post('/articles/{article}/publish', [ArticleController::class, 'publishArticle']);

While this approach works, it diverges from the convention that Laravel's resource() helper establishes. The resource() method automatically generates six routes based on the controller name and expects methods named index, show, create, store, edit, update, and destroy. If you add a new method like export to your resource controller, it will not automatically create a route unless you manually specify it using the only() or except() helpers.

Route::resource('articles', ArticleController::class)
    ->only(['index', 'show', 'export']);

This pattern is useful for keeping your API clean but can become cumbersome if you have many custom methods. In such cases, it is often better to decouple the logic entirely from the resource controller convention and use a generic Controller class or an ApiResourceController subclass where you define all routes manually. This avoids the mental overhead of remembering which default method names are reserved for the automatic route generation.

A common pitfall arises when developers assume that adding a method to a resource controller automatically creates a new URL. Without manual route registration, the method remains dead code unless accessed directly via a generated link or an internal call. Always verify that your routes/*.php file contains the necessary definitions for every public method you intend to expose as an HTTP endpoint.

Another consideration is maintaining separation of concerns. If your custom method performs actions unrelated to the standard resource lifecycle (like sending emails, processing payments, or generating files), consider whether a dedicated controller class might be more appropriate. This keeps your codebase organized and prevents the ArticleController from becoming a monolithic dump of logic that doesn't fit the CRUD pattern.

If you are building an API, remember that Laravel's JSON resource responses (JsonResource) are distinct from the request/response methods in the controller. You can add custom methods to handle side effects (like logging or notifications) while still returning standard JsonResource objects for read operations. Just ensure your method signatures match what you expect in your route definitions.

For complex applications, utilizing Laravel's service container or registering middleware specific to these new endpoints can further secure and manage the flow of data. Always validate your input within these custom methods, as they often lack the strict validation scaffolding that might be present in standard form request classes unless explicitly configured.

Our network