Mapping views to routes | 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-views  Mapping views to routes

 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)

 Mapping views to routes
=======================

The package will add a route for each `blade.php` that it finds in [directory you've specified](getting-started).

Imagine you've configured view discovery this way.

```
// config/route-discovery

'discover_views_in_directory' => [
    'docs' => resource_path('views/docs'),
],
```

And image that `views/docs` contains these Blade views...

- index.blade.php
- pageA.blade.php
- pageB.blade.php
- nested/index.blade.php
- nested/pageC.blade.php

... then these routes will be registered:

- /docs --&gt; index.blade.php
- /docs/page-a --&gt; pageA.blade.php
- /docs/page-b --&gt; pageB.blade.php
- /docs/nested --&gt; nested/index.blade.php
- /docs/nested/page-c --&gt; nested/pageC.blade.php

The registered routes will also be named automatically. The route name will be generated by replacing the `/` with `.`. So there routes will have these names:

- /docs --&gt; docs
- /docs/page-a --&gt; docs.page-a
- /docs/page-b --&gt; docs.page-b
- /docs/nested --&gt; docs.nested
- /docs/nested/page-c --&gt; docs.nested.page-c
