Introduction | laravel-route-discovery | Spatie

 SPATIE

  Laravel Route Discovery
==========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-route-discovery](https://spatie.be/docs/laravel-route-discovery/v1)  Introduction

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-route-discovery/v1)

- [ Introduction ](https://spatie.be/docs/laravel-route-discovery/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-route-discovery/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-route-discovery/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-route-discovery/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-route-discovery/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-route-discovery/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-route-discovery/v1/about-us)

Discovering routes for controllers
----------------------------------

- [ Getting started ](https://spatie.be/docs/laravel-route-discovery/v1/discovering-routes-for-controllers/getting-started)
- [ Mapping controllers to routes ](https://spatie.be/docs/laravel-route-discovery/v1/discovering-routes-for-controllers/mapping-controllers-to-routes)

Discovering routes for views
----------------------------

- [ Discovering routes for views ](https://spatie.be/docs/laravel-route-discovery/v1/discovering-routes-for-views/getting-started)
- [ Mapping views to routes ](https://spatie.be/docs/laravel-route-discovery/v1/discovering-routes-for-views/mapping-views-to-routes)

Advanced usage
--------------

- [ Using route transformers ](https://spatie.be/docs/laravel-route-discovery/v1/advanced-usage/using-route-transformers)

 Laravel Route Discovery
=========================

 Automatically discover routes in a Laravel app

 [    Repository ](https://github.com/spatie/laravel-route-discovery)

    42,649

    234

Introduction
------------

###  On this page

1. [ A note on performance ](#content-a-note-on-performance)

This package can automatically discover routes for controllers and views in your Laravel application. This isn't an all-in approach. While using 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 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() { /* ... */ }
}
```

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.
