spatie / laravel-route-discovery
Auto register routes using PHP attributes
Installs: 19 519
Dependents: 1
Suggesters: 0
Security: 0
Stars: 226
Watchers: 3
Forks: 27
Open Issues: 1
Requires
- php: ^8.0
- illuminate/contracts: ^8.67|^9.0|^10.0|^11.0
- illuminate/support: ^8.77|^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.10
- symfony/finder: ^5.4.2|^6.0|^7.0
Requires (Dev)
- nunomaduro/larastan: ^1.0.2|^2.0
- orchestra/testbench: ^6.23.2|^7.0|^8.0|^9.0
- pestphp/pest: ^1.21|^2.34
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.27
README
This package can automatically discover routes for controllers and views in your Laravel application. This isn't an all-in approach. While using use auto discovery, you can still register routes like you're used to.
// typically in a routes file Discover::controllers()->in($whateverDirectoryYouPrefer); Discover::views()->in($whateverDirectoryYouPrefer); // other routes
Using PHP attributes you can manipulate discovered routes: you can set a route name, add some middleware, or ...
Here's how you would add middleware to a controller whose's route will be auto discovered.
namespace App\Http\Controllers; use Illuminate\Routing\Middleware\ValidateSignature; use Spatie\RouteDiscovery\Attributes\Route; class MyController { #[Route(middleware: ValidateSignature::class)] public function myMethod() { /* ... */ } }
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Documentation
You'll find full documentation at the Spatie website.
A note on performance
Discovering routes during each application request may have a small impact on performance. For increased performance, we highly recommend caching your routes as part of your deployment process.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.