Skip to content

API Route Auto Discovery #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

johntrickett86
Copy link

This PR introduces a new feature to the laravel-orion package that enables automatic route discovery and registration. This eliminates the need to manually register routes for each controller, making the package more convenient to use and reducing boilerplate code.

This is something that I found I was implementing on my own projects so I could move quickly when building simple APIs.

Key Features

  • Automatic Controller Discovery: The package now automatically scans specified directories for controllers and registers their routes.
  • Configurable Paths: You can specify which directories to scan for controllers in the config file.
  • Opt-out Mechanism: Controllers can opt out of automatic route discovery by using the DisableRouteDiscovery trait.
  • Customizable Route Configuration: Controllers can customize their route prefix, middleware, and other settings.

Implementation Details

  • Added HandlesRouteDiscovery trait to provide route registration functionality
  • Added DisableRouteDiscovery trait to allow controllers to opt out
  • Updated BaseController to include the route discovery functionality
  • Enhanced OrionServiceProvider to discover and register controllers
  • Added configuration options in config/orion.php

If you believe this would be a useful feature, then I would be happy to submit a PR to the docs to update.

- Updated the config file
- Added new route discovery trait
- Updated service provider
- Added the ability to disable route discovery at controller level
@johntrickett86
Copy link
Author

Just to note: the use of the switch expression in the HandlesRouteDiscovery trait made me sick in my mouth a bit, but as the minimum supported PHP version is pre version 8.0, using a match statement was not possible!

@johntrickett86
Copy link
Author

@alexzarbn Let me know your thoughts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant