Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Route Discovery Laravel Package

spatie/laravel-route-discovery

Automatically discover Laravel routes by scanning controllers and views instead of manually defining them. Configure discovery in your routes files and use PHP attributes to customize names, middleware, and more for each discovered route.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Developer Productivity: Accelerates API/route development by reducing boilerplate (e.g., Route::get(), Route::post()) and consolidating route definitions into controllers via PHP attributes. Aligns with modern PHP (8.0+) attribute support.
  • API-First Roadmap: Ideal for teams prioritizing API-driven architectures (e.g., GraphQL, REST, or microservices) where route discovery reduces coupling between routes and routes/web.php/routes/api.php.
  • Build vs. Buy: Buy—avoids reinventing route discovery logic while maintaining Laravel’s ecosystem compatibility. Lower maintenance cost than custom solutions.
  • Use Cases:
    • Microservices: Auto-discover routes across modular services without manual registration.
    • Legacy Refactoring: Migrate monolithic route files to attribute-based controllers incrementally.
    • API-First Startups: Rapidly prototype endpoints with minimal upfront configuration.
    • Internal Tools: Quickly expose admin/CLI routes without polluting main route files.

When to Consider This Package

  • Adopt When:
    • Your team uses Laravel 8+ (PHP 8.0+ attributes required).
    • You have >50 routes or frequent route changes (reduces maintenance overhead).
    • Developing APIs/microservices where route discovery aligns with modular design.
    • Prioritizing developer velocity over fine-grained route control (e.g., complex middleware per route).
  • Look Elsewhere If:
    • You need legacy Laravel (<8.0) support (attributes not available).
    • Routes require highly dynamic or runtime-generated paths (attributes are compile-time).
    • Your team prefers explicit route definitions (e.g., for auditability or complex route logic).
    • Using non-Laravel frameworks (e.g., Symfony, Express) or monolithic route files are preferred.

How to Pitch It (Stakeholders)

For Executives:

"This package automates Laravel route registration using PHP attributes, cutting route-definition time by 30–50% for API-heavy apps. By moving routes into controllers (where they logically belong), we reduce technical debt, accelerate feature delivery, and align with modern PHP practices. Low-risk adoption (MIT license, Spatie-backed) with proven scalability in microservices. ROI: Faster dev cycles, fewer bugs from misconfigured routes."

For Engineering:

*"Leverage spatie/laravel-route-discovery to:

  • Eliminate boilerplate: Replace Route::get() calls with [Route] attributes on controllers/methods.
  • Decouple routes: Discover routes dynamically from directories (e.g., Discover::controllers()->in(app_path('Http/Controllers/API'))).
  • Enforce consistency: Standardize route naming/middleware via attributes (e.g., @Route(name: 'api.users.index')).
  • Future-proof: Works seamlessly with Laravel’s ecosystem (e.g., API resources, testing). Tradeoff: Less explicit route control, but gains in maintainability and speed. Ideal for APIs or modular services."*

Example Migration Path:

  1. Start with a single controller directory (e.g., app/Http/Controllers/API).
  2. Add attributes to methods: [Route('users', methods: ['GET'])].
  3. Replace routes/api.php with Discover::controllers()->in(app_path('Http/Controllers/API')).
  4. Gradually expand to other modules.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport