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

- [ ホーム ](/ja/) 
/
- [ 作成方法 ](/ja/how-to-create/) 
/
- Laravelガイド            
# Laravel向け`llms.txt`

Laravel の public/ ディレクトリは Web ルートなので、設定は不要です。動的生成する場合は routes/web.php にルートを追加するか、Laravel の Cache facade を使う専用コントローラーを追加します。

最終更新: 2026年4月22日

このページの内容

- [ オプション 1：public/ 内の静的ファイル ](#static)
- [ オプション2：routes/web.php のルート ](#route)
- [ 選択肢3：キャッシュ付きコントローラー ](#controller)
- [ 再利用可能にするレスポンスマクロ ](#macro)
- [ 検証 ](#verify)
- [ リリース前のチェックリスト ](#checklist)              
警告

Bladeテンプレートは使用しないでください

決して Blade ビューを返してはならない  llms.txt . Blade は HTML コメント、空白、
プレーンテキスト形式を壊す doctype 宣言を追加します。常に生の  response()  で  Content-Type: text/plain .

## オプション 1：public/ 内の静的ファイル

Laravelの `public/` ディレクトリはnginxまたはApacheが配信するドキュメントルートです。そこに置いたファイルは、ルーティング設定なしで
対応するURLパスから利用できます。これは最も簡単な方法で、コード変更は一切必要ありません。
public/llms.txt, directory structure    コピー     

```
# 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.

```

この方法は、Laravelのすべてのデプロイ先で利用できます： **Laravel Forge**, **Laravel Vapor**, **Heroku**, **Railway**およびベア VPS
サーバーです。Web サーバー（nginx/Apache）が PHP
を介さずにファイルを直接配信するため、より高速でもあります。

## オプション2：routes/web.php のルート

コンテンツをプログラムで生成したり、ファイルではなくコードから管理したりしたい場合は、
に名前付きルートを追加してください。 `routes/web.php`:
routes/web.php    コピー     

```
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');

```

PHPのheredoc構文（`  
例

ルートの配置

次のルートを登録します：  /llms.txt  ルートをcatch-allまたはフォールバックルート（ Route::fallback() ) これにより、Laravel が正しく対応できるようになります。

## 選択肢3：キャッシュ付きコントローラー

データベースから動的に生成されるコンテンツ（例：公開済みの
ドキュメントページの取得）については、専用の呼び出し可能なコントローラーを使用し、 `Cache::remember()` リクエストごとにデータベースクエリを実行することを避けるために：
app/Http/Controllers/LlmsTxtController.php    コピー     

```
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    コピー     

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

```

`Cache::remember()` 設定されたキャッシュドライバー（Redis、Memcached、 データベース、またはファイル）に結果を保存します。キャッシュは3600秒後に自動的に再生成されます。コンテンツの更新直後に
キャッシュを無効化するには、 `Cache::forget('llms_txt')` モデルのオブザーバー内、またはデプロイメントフックの後に実行してください。

## 再利用可能にするレスポンスマクロ

複数のプレーンテキストファイルを提供する場合、またはアプリケーション全体で一貫したパターンを確保したい場合は、
以下を登録してください。 `plaintext()` response マクロ内 `AppServiceProvider`:
app/Providers/AppServiceProvider.php    コピー     

```
'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);

```

このマクロは、アプリケーション内のどこからでも次を介して利用できます： `response()->plaintext($content)`、 `Content-Type` および `Cache-Control` ヘッダーの一貫性を保ちます。

## 検証

デプロイ後、ファイルが正しく配信されていることを確認します:
Verification    コピー     

```
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
```

次に URL を [llms.txt バリデーター](/ja/validator/) で仕様への完全な準拠を確認します。

## リリース前のチェックリスト

- ファイルの配信先： `/llms.txt` で `200 OK`. 
- `Content-Type: text/plain; charset=utf-8` が設定されていること。 
- `Cache-Control` ヘッダーが存在します。 
- レスポンスはプレーンテキストで、HTML も Blade の出力もありません。 
- 先頭に H1 見出しがちょうど1つあること。 
- H1の直後にブロッククォートの要約を配置する。 
- すべてのURLは絶対パスである（`https://`). 
- この `/llms.txt` ルートに配置します。 
- バリデーターでエラーが返されないこと： [llmtxt.info/validator/](/ja/validator/)   
## 関連ガイド

- [llms.txtの作成方法](/ja/how-to-create/)、テンプレート、チェックリスト。 
- [llms.txt フォーマットリファレンス](/ja/llms-txt-format/)、仕様の詳細。 
- [ヘッドレスCMS向けllms.txt](/ja/llms-txt-cms/)、Contentful、Sanity、Strapi。 
- [ベストプラクティス](/ja/best-practices/)、含めるものと省くもの。 
- [バリデータ](/ja/validator/) · [ジェネレーター](/ja/generator/).        
## ソース

- [ llmstxt.org、コミュニティによる提案 ](https://llmstxt.org/)
- [ Laravelドキュメント、ルーティング ](https://laravel.com/framework/docs/routing)
- [ Laravelのドキュメント、キャッシュ ](https://laravel.com/framework/docs/cache)
