<!-- Generated from llms-txt-laravel/index.html. The canonical document is the HTML page. -->

- [ Home ](/) 
/
- [ How to create ](/how-to-create/) 
/
- Laravel guide            
# llms.txt for Laravel

Laravel's public/ directory is the web root, zero config. For dynamic generation, add a route in routes/web.php or a dedicated controller with Laravel's Cache facade.

Last updated: April 22, 2026

⚠ Do NOT use Blade templates

Never return a Blade view for  llms.txt . Blade adds HTML comments, whitespace, and
doctype declarations that break the plain-text format. Always return a raw  response()  with  Content-Type: text/plain .

## Option 1: static file in public/

Laravel&rsquo;s `public/` directory is the document root served by nginx or Apache. Any
file placed there is available at the corresponding URL path with no routing configuration. This is
the simplest approach and requires zero code changes.
public/llms.txt, directory structure   
Copy

```
# Laravel static file approach
#
# Laravel's public/ directory is the web root (served by nginx/Apache).
# Drop your file here and it is immediately available at /llms.txt.
#
# Project structure:
# your-laravel-app/
# ├── public/
# │   ├── index.php
# │   └── llms.txt   ← add this
# ├── routes/
# └── app/
#
# No code change needed. Works on Forge, Vapor, Heroku, and bare VPS.

```

This approach works with all Laravel deployment targets: **Laravel Forge**, **Laravel Vapor**, **Heroku**, **Railway**, and bare VPS
servers. The web server (nginx/Apache) serves the file directly without involving PHP, which is
also faster.

## Option 2: route in routes/web.php

When you want to generate the content programmatically or manage it from code rather than a
file, add a named route in `routes/web.php`:
routes/web.php   
Copy

```
One-sentence description of what your site or product does.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure in minutes.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog with examples.

## Product

- [Overview](https://yoursite.com/product): Core features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing details.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
LLMS;

return response($content, 200)
->header('Content-Type', 'text/plain; charset=utf-8')
->header('Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');
})->name('llms-txt');

```

Use PHP&rsquo;s heredoc syntax (`  
✓ Route placement

Register the  /llms.txt  route before any catch-all or fallback routes ( Route::fallback() ) to ensure Laravel matches it correctly.

## Option 3: controller with caching

For content generated dynamically from the database, for example, pulling published
documentation pages, use a dedicated invokable controller with `Cache::remember()` to avoid a database query on every request:
app/Http/Controllers/LlmsTxtController.php   
Copy

```
buildContent();
});

return response($content, 200)
->header('Content-Type', 'text/plain; charset=utf-8')
->header('Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');
}

private function buildContent(): string
{
// You can query your database here:
// $docs = \App\Models\Doc::published()->get();
// $links = $docs->map(fn($d) => "- [{$d->title}](https://yoursite.com/docs/{$d->slug}): {$d->summary}")->join("\n");

return   One-sentence description of your product.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure in minutes.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog with examples.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
LLMS;
}
}

```
routes/web.php, controller registration   
Copy

```
name('llms-txt');

```

`Cache::remember()` stores the result in your configured cache driver (Redis, Memcached,
database, or file). The cache is regenerated automatically after 3600 seconds. To invalidate immediately
after a content update, call `Cache::forget('llms_txt')` in your model&rsquo;s observer or after a deployment hook.

## Response macro for reusability

If you serve multiple plain-text files or want a consistent pattern across your application,
register a `plaintext()` response macro in `AppServiceProvider`:
app/Providers/AppServiceProvider.php   
Copy

```
'text/plain; charset=utf-8',
'Cache-Control' => "public, max-age={$maxAge}, stale-while-revalidate=86400",
]);
});
}
}

// Usage in a route or controller:
// return response()->plaintext($content);

```

The macro is then available anywhere in your application via `response()->plaintext($content)`, keeping the `Content-Type` and `Cache-Control` headers consistent.

## Verify

After deploying, confirm the file is served correctly:
Verification   
Copy

```
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8
# cache-control: public, max-age=3600

curl https://yoursite.com/llms.txt | head -5
# Should print: # Your Site
```

Then paste the URL into the [llms.txt validator](/validator/) for full spec compliance
checking.

## Checklist before shipping

- File served at `/llms.txt` with `200 OK`. 
- `Content-Type: text/plain; charset=utf-8` is set. 
- `Cache-Control` header is present. 
- Response is plain text, no HTML, no Blade output. 
- Exactly one H1 heading at the top. 
- Blockquote summary immediately after the H1. 
- All URLs are absolute (`https://`). 
- No auth middleware applied to the `/llms.txt` route. 
- Validator returns no errors: [llmtxt.info/validator/](/validator/)   
## Related guides

- [How to create llms.txt](/how-to-create/), templates and checklist. 
- [llms.txt format reference](/llms-txt-format/), spec details. 
- [llms.txt for headless CMS](/llms-txt-cms/), Contentful, Sanity, Strapi. 
- [Best practices](/best-practices/), what to include and what to skip. 
- [Validator](/validator/) · [Generator](/generator/).        
## Sources

- [ llmstxt.org, official spec ](https://llmstxt.org/)
- [ Laravel docs, routing ](https://laravel.com/docs/routing)
- [ Laravel docs, cache ](https://laravel.com/docs/cache)           
On this page

- [ Option 1: static file in public/ ](#static)
- [ Option 2: route in routes/web.php ](#route)
- [ Option 3: controller with caching ](#controller)
- [ Response macro for reusability ](#macro)
- [ Verify ](#verify)
- [ Checklist before shipping ](#checklist)
