Installation &amp; setup | 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)  Installation &amp; setup

 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)

 Installation &amp; setup
========================

###  On this page

1. [ Publishing the config file ](#content-publishing-the-config-file)
2. [ A word on performance ](#content-a-word-on-performance)

You can install the package via composer:

```
composer require spatie/laravel-route-discovery
```

Publishing the config file
--------------------------------------------------------------------------------------------------------------------------------------

Optionally, you can publish the `route-discovery` config file with this command.

```
php artisan vendor:publish --tag="route-discovery-config"
```

This is the content of the published config file:

```
return [
    /*
     * Routes will be registered for all controllers found in
     * these directories.
     */
    'discover_controllers_in_directory' => [
        // app_path('Http/Controllers'),
    ],

    /*
     * Routes will be registered for all views found in these directories.
     * The key of an item will be used as the prefix of the uri.
     */
    'discover_views_in_directory' => [
        // 'docs' => resource_path('views/docs'),
    ],

    /*
     * After having discovered all controllers, these classes will manipulate the routes
     * before registering them to Laravel.
     *
     * In most cases, you shouldn't change these.
     */
    'pending_route_transformers' => [
        ...Spatie\RouteDiscovery\Config::defaultRouteTransformers(),
        //
    ],
];
```

A word 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.
