laravel-routes-best-practices

Refactor Laravel route closures into controller-backed routes with middleware.

Updated Jun 8, 2025
One-click install
npx skills add https://github.com/noartem/kawa --skill laravel-routes-best-practices-noartem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-routes-best-practices
Source: https://github.com/noartem/kawa/tree/main/ui/.ai/skills/laravel-routes-best-practices
Command: npx skills add https://github.com/noartem/kawa --skill laravel-routes-best-practices-noartem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Laravel route files often accumulate business logic, validation, and database interactions, which makes maintenance and testing harder. This Skill guides you to keep routes minimal and delegate work to controllers and form requests.

Core Features & Use Cases

  • Separation of concerns: routes map to controllers and middleware handles validations.
  • Organization: use route groups, prefixes, and named routes for clarity.
  • Use Case: Convert an existing route closure that performs validation into a route that delegates to a dedicated controller and a CancelOrderRequest for input validation.

Quick Start

Refactor an existing route closure that contains business logic into a controller-backed route.

Frequently Asked Questions about laravel-routes-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I move business logic out of my Laravel routes?

To move business logic out of Laravel routes, refactor route closures to delegate work to dedicated controllers and form requests. This separates concerns and keeps route files minimal.

What is the best way to organize Laravel routes for web and API?

The best way to organize Laravel routes is using route groups, prefixes, and named routes. This structure keeps web and API routes clean, controller-focused, and easier to maintain.

Should I use closures or controllers for Laravel route definitions?

You should use controllers instead of closures for Laravel route definitions. Delegating to controllers prevents business logic and database interactions from accumulating directly inside route files, ensuring better separation of concerns.

Where should Laravel route validation logic go?

Laravel route validation logic should go into form requests and middleware rather than route closures. Delegating validation to dedicated request classes keeps routes clean and controller-focused.

How do I convert a Laravel route closure to use a controller and form request?

To convert a Laravel route closure, map the route to a dedicated controller method and replace inline validation with a form request like CancelOrderRequest. This delegates work away from the route definition.