Getting started | 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)  Discovering-routes-for-controllers  Getting started

 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)

 Getting started
===============

###  On this page

1. [ Via the routes file ](#content-via-the-routes-file)
2. [ Via the config file ](#content-via-the-config-file)

This package can automatically discover and register routes for a directory containing controllers.

Via the routes file
-----------------------------------------------------------------------------------------------------------------

You can enable route discovery via the routes file.

```
// in a routes file

use Spatie\RouteDiscovery\Discovery\Discover;

Discover::controllers()->in(app_path('Http/Controllers'));
```

Via the config file
-----------------------------------------------------------------------------------------------------------------

Alternatively, you can discover routes using the config file.

First, you need to publish the config file. This will create a file at `config/route-discovery.php`

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

In the `discover_controllers_in_directory` key of the `route-discovery` config file, you can specify a directory that contains controllers.

Here you can uncomment the line to register controllers in the `app_path('Http/Controllers')` directory. Of course you can use any directory you want.

```
// config/route-discovery

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