> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel Folio

> Learn how to implement file-based routing with Laravel Folio, from installation to route model binding.

## Introduction

Laravel Folio is a page-based router that lets you define routes just by placing Blade files.
Unlike the traditional `routes/web.php`-centric approach, it reflects your file system structure directly in your URLs.

It's especially useful for content-focused sites and admin panels where you want to quickly add pages screen by screen.
For areas that need fine-grained HTTP control like APIs, it's practical to combine Folio with regular routing.

## Installation

First, add Folio via Composer.

```bash theme={null}
composer require laravel/folio
php artisan folio:install
```

`folio:install` registers Folio's service provider.
By default, `resources/views/pages/` is the pages directory.
When using multiple page directories or base URIs, configure them with `Folio::path()` and `uri()` in your service provider's `boot` method.

```php theme={null}
use Laravel\Folio\Folio;

Folio::path(resource_path('views/pages/guest'))->uri('/');

Folio::path(resource_path('views/pages/admin'))
    ->uri('/admin');
```

## Creating routes

Folio automatically generates URLs from the Blade file names under the mounted directory.

```text theme={null}
resources/views/pages/schedule.blade.php -> /schedule
```

```bash theme={null}
php artisan folio:list
```

### Nested routes

When you nest directories, the URLs are nested with the same structure.

```bash theme={null}
php artisan folio:page user/profile
# pages/user/profile.blade.php -> /user/profile
```

### Index routes

`index.blade.php` is mapped to the root of that directory.

```bash theme={null}
php artisan folio:page index
# pages/index.blade.php -> /

php artisan folio:page users/index
# pages/users/index.blade.php -> /users
```

## Route parameters

You can capture URL segments using `[]` in the file name.

```bash theme={null}
php artisan folio:page "users/[id]"
# pages/users/[id].blade.php -> /users/1
```

```blade theme={null}
<div>User {{ $id }}</div>
```

To capture multiple segments, use `...`.

```bash theme={null}
php artisan folio:page "users/[...ids]"
# pages/users/[...ids].blade.php -> /users/1/2/3
```

```blade theme={null}
@foreach ($ids as $id)
    <li>User {{ $id }}</li>
@endforeach
```

## Route model binding

If you use a model name like `[User].blade.php`, the model is resolved automatically.

```bash theme={null}
php artisan folio:page "users/[User]"
# pages/users/[User].blade.php -> /users/1
```

```blade theme={null}
<div>User {{ $user->id }}</div>
```

To also handle soft-deleted models, call `withTrashed()` inside the page.

```php theme={null}
<?php

use function Laravel\Folio\withTrashed;

withTrashed();
```

<Info>
  With a file name like `[Post:slug].blade.php`, you can resolve models by keys other than `id` (for example, `slug`).
</Info>

## Middleware

To apply middleware only to a specific page, use `middleware()` inside the page template.

```php theme={null}
<?php

use function Laravel\Folio\middleware;

middleware(['auth', 'verified']);
```

To apply middleware to multiple pages at once, use `Folio::path(...)->middleware()`.

```php theme={null}
<?php

use Laravel\Folio\Folio;

Folio::path(resource_path('views/pages'))->middleware([
    'admin/*' => ['auth', 'verified'],
]);
```

## Named routes

You can name a Folio page with `name()` as well.

```php theme={null}
<?php

use function Laravel\Folio\name;

name('users.index');
```

<Info>
  If you define `name('users.show')` on a page like `users/[User].blade.php`, you can generate parameterized URLs with `route('users.show', ['user' => $user])`.
</Info>

You can generate URLs with the assigned route name using the `route()` helper.

```php theme={null}
route('users.index');
route('users.show', ['user' => $user]);
```

## Mapping between files and URLs

```mermaid theme={null}
graph LR
  A["pages/index.blade.php"] --> B["/"]
  C["pages/about.blade.php"] --> D["/about"]
  E["pages/users/[User].blade.php"] --> F["/users/1"]
```

## Comparison with traditional routing

| Feature          | Regular routing                  | Folio                                  |
| ---------------- | -------------------------------- | -------------------------------------- |
| Route definition | `routes/web.php`                 | Automatic via file name                |
| Controllers      | Required (or a closure)          | Not required (write directly in Blade) |
| Well-suited for  | APIs, SPAs, complex HTTP control | Content sites, admin panels            |

<Tip>
  Even when using Folio, enabling the route cache with `php artisan route:cache` optimizes production performance.
</Tip>


## Related topics

- [Application Structure in Laravel 11 and Later](/en/advanced/app-structure.md)
- [Laravel Boost](/en/boost.md)
- [Laravel Telescope](/en/telescope.md)
- [Laravel Bluesky](/en/packages/laravel-bluesky/index.md)
- [Laravel Octane](/en/octane.md)
