https://github.com/spatie/laravel-route-discovery
Automatically discover routes in a Laravel app
https://github.com/spatie/laravel-route-discovery
discovery laravel php route
Last synced: about 2 months ago
JSON representation
Automatically discover routes in a Laravel app
- Host: GitHub
- URL: https://github.com/spatie/laravel-route-discovery
- Owner: spatie
- License: mit
- Created: 2021-12-29T16:04:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-17T10:01:43.000Z (5 months ago)
- Last Synced: 2025-04-07T04:07:41.525Z (3 months ago)
- Topics: discovery, laravel, php, route
- Language: PHP
- Homepage: https://spatie.be/docs/laravel-route-discovery
- Size: 232 KB
- Stars: 229
- Watchers: 4
- Forks: 28
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Support: docs/support-us.md
Awesome Lists containing this project
README
![]()
Automatically discover routes in a Laravel app
[](https://packagist.org/packages/spatie/laravel-route-discovery)

[](https://packagist.org/packages/spatie/laravel-route-discovery)
```php
// typically in a routes fileDiscover::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.
```php
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
[
](https://spatie.be/github-ad-click/laravel-route-discovery)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Documentation
You'll find full documentation [at the Spatie website](https://spatie.be/docs/laravel-route-discovery).
## 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](https://laravel.com/docs/8.x/routing#route-caching) as part of your deployment process.
## Testing
``` bash
composer test
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.