PHPackages                             sagarchauhan005/laravel-llms-txt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. sagarchauhan005/laravel-llms-txt

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

sagarchauhan005/laravel-llms-txt
================================

Laravel package for llms.txt standard - serves /llms.txt endpoint and provides Human/Machine markdown views for SSR pages

v0.1.1(2mo ago)040MITPHPPHP ^7.2.5|^8.0CI passing

Since Feb 12Pushed 2mo agoCompare

[ Source](https://github.com/sagarchauhan005/laravel-agent-response)[ Packagist](https://packagist.org/packages/sagarchauhan005/laravel-llms-txt)[ RSS](/packages/sagarchauhan005-laravel-llms-txt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (5)Used By (0)

Laravel llms.txt Package
========================

[](#laravel-llmstxt-package)

A Laravel package that implements the [llms.txt standard](https://llmstxt.org/) to help agents scrape and read SSR web pages more easily, in fewer tokens, with the most useful information.

Features
--------

[](#features)

- **`/llms.txt` endpoint**: Serves a standards-compliant llms.txt file with curated links and information
- **Per-route Human/Machine views**: Automatically generate markdown versions of any route (like [parallel.ai/pricing](https://parallel.ai/pricing))
    - **`.md` extension**: Access `/pricing.md` to get markdown version of `/pricing`
    - **Query parameter**: Use `?view=machine` or `?format=markdown`
    - **Accept header**: Send `Accept: text/markdown` header
- **Use-case presets**: Pre-configured templates for Docs, Business, E-commerce, Education, and Legislation
- **Cache headers**: Configurable HTTP cache headers for all markdown responses
- **Main content extraction**: Optionally extract only main content (e.g. `main`, `.prose`) to reduce tokens

Philosophy and best practices
-----------------------------

[](#philosophy-and-best-practices)

llms.txt is meant to be a **high‑signal index for agents**, not an exhaustive dump of every URL on your site. This package is designed around a few principles:

- **Curated, not crawled**: You explicitly choose the most important pages (docs, pricing, policies, key flows) instead of auto‑discovering every route. This keeps the file small, readable, and cheap to consume in tokens.
- **Stable entry points**: llms.txt should highlight URLs that are unlikely to change often (collections, category indexes, key docs, sitemap URLs) rather than every product page or blog post.
- **One source of truth**: All content comes from `config/llms-txt.php` (plus your own extensions if you want), so you can review changes in code review and keep it in version control.

### Recommended setup

[](#recommended-setup)

- **Start small**:
    - Add a handful of sections (e.g. `Getting Started`, `Products`, `Policies`, `Support`).
    - Link to category/index pages, not every individual item.
- **Use presets**:
    - Pick the closest `use_case` (`docs`, `business`, `ecommerce`, `education`, `legislation`) and then fill in the `sections` for that shape rather than designing your own from scratch.
- **Keep it human‑readable**:
    - Use clear titles and short `notes` so humans and agents both understand why a link matters.
    - Avoid dumping raw query URLs, deep pagination, or “internal only” tools.
- **Limit size**:
    - Prefer linking to sitemaps (`/sitemap.xml`, `/products-sitemap.xml`) or collection pages for huge catalogs.
    - If you generate links dynamically (e.g. from products/categories), limit to featured/top N items.

In practice, treat llms.txt like a **README for agents**: the place you intentionally point them at the best starting points instead of making them guess or crawl the entire site.

### Dynamic content examples

[](#dynamic-content-examples)

For larger, dynamic sites (like e‑commerce), you can keep the llms.txt philosophy and still generate parts of it from your database:

- **Products section**: instead of every SKU, expose just featured/top N products:

    ```
    // In a custom LlmsTxtService in your app
    $config['sections']['Products'] = Product::query()
        ->where('is_featured', true)
        ->limit(100)
        ->get()
        ->map(fn ($product) => [
            'title' => $product->name,
            'url'   => route('product.show', $product),
            'notes' => $product->short_description,
        ])
        ->all();
    ```
- **Categories/Collections section**: list stable entry points:

    ```
    $config['sections']['Categories'] = Category::query()
        ->orderBy('name')
        ->get()
        ->map(fn ($category) => [
            'title' => $category->name,
            'url'   => route('category.show', $category),
        ])
        ->all();
    ```
- **Sitemaps**: for very large catalogs, add links to your sitemaps instead of every product:

    ```
    $config['sections']['Optional'][] = [
        'title' => 'Product sitemap',
        'url'   => url('/products-sitemap.xml'),
        'notes' => 'All product URLs for crawlers and agents',
    ];
    ```

This keeps llms.txt concise and high‑value, while still giving agents a path to the full structure.

Installation
------------

[](#installation)

```
composer require sagarchauhan005/laravel-llms-txt
```

Publish the configuration file:

```
php artisan vendor:publish --tag=llms-txt-config
```

Configuration
-------------

[](#configuration)

Edit `config/llms-txt.php`:

```
return [
    'enabled' => true,
    'path' => 'llms.txt',
    'use_case' => 'docs', // 'docs', 'business', 'ecommerce', 'education', 'legislation', 'custom'
    'title' => config('app.name'),
    'description' => 'Your project description here',
    'sections' => [
        'Getting Started' => [
            ['title' => 'Quick Start', 'url' => '/docs/quick-start', 'notes' => 'Get started in 5 minutes'],
        ],
        'Optional' => [
            ['title' => 'External Docs', 'url' => 'https://example.com/docs'],
        ],
    ],
    'machine_view_enabled' => true,
    'md_extension_enabled' => true,
    'main_content_selector' => 'main', // CSS selector for main content
    'cache_enabled' => true,
    'cache_max_age' => 3600, // 1 hour
];
```

Usage
-----

[](#usage)

### Basic llms.txt

[](#basic-llmstxt)

Once configured, visit `/llms.txt` to see your llms.txt file.

### Human/Machine Views

[](#humanmachine-views)

The package automatically provides markdown versions of your routes:

**Option 1: `.md` extension**

```
GET /pricing.md → Returns markdown version of /pricing
GET /about.md → Returns markdown version of /about

```

**Option 2: Query parameter**

```
GET /pricing?view=machine → Returns markdown version
GET /pricing?format=markdown → Returns markdown version

```

**Option 3: Accept header**

```
GET /pricing
Accept: text/markdown

```

### Adding a Human/Machine Toggle

[](#adding-a-humanmachine-toggle)

Add this to your Blade layout:

```

    Human
    Machine

```

Or use a simple toggle:

```
@if(request()->query('view') === 'machine')
    Human View
@else
    Machine View
@endif
```

Use Case Presets
----------------

[](#use-case-presets)

### Docs/APIs

[](#docsapis)

```
'use_case' => 'docs',
```

Provides sections: Getting Started, API Reference, Optional

### Business/Personal

[](#businesspersonal)

```
'use_case' => 'business',
```

Provides sections: About, Policies, Contact, Optional

### E-commerce

[](#e-commerce)

```
'use_case' => 'ecommerce',
```

Provides sections: Products, Policies, Support, Optional

### Education

[](#education)

```
'use_case' => 'education',
```

Provides sections: Courses, Resources, Optional

### Legislation

[](#legislation)

```
'use_case' => 'legislation',
```

Provides sections: Overview, Sections, Optional

Environment Variables
---------------------

[](#environment-variables)

### Minimal setup (recommended defaults)

[](#minimal-setup-recommended-defaults)

For most apps you only need a few env vars; everything else can stay in `config/llms-txt.php`:

```
LLMS_TXT_ENABLED=true
LLMS_TXT_DESCRIPTION="Short, high-signal summary of what this site is for"
LLMS_TXT_USE_CASE=docs   # or: business / ecommerce / education / legislation / custom
LLMS_TXT_TITLE="My App"  # optional; falls back to APP_NAME
```

Then define your actual links in `config/llms-txt.php` under the `sections` key.

### Advanced tuning (optional)

[](#advanced-tuning-optional)

Only reach for these when you have a concrete reason (performance, SEO, or custom behavior):

```
# Endpoint / routing
LLMS_TXT_PATH=llms.txt

# Machine view behavior
LLMS_TXT_MACHINE_VIEW_ENABLED=true
LLMS_TXT_MD_EXTENSION_ENABLED=true
LLMS_TXT_MACHINE_VIEW_TRIGGER=all   # query | accept | header | all
LLMS_TXT_MAIN_CONTENT_SELECTOR=main # optional CSS selector for "main" content
LLMS_TXT_MACHINE_VIEW_MAX_HTML_LENGTH=500000 # optional safety limit for very large HTML pages

# Caching
LLMS_TXT_CACHE_ENABLED=true
LLMS_TXT_CACHE_MAX_AGE=3600
LLMS_TXT_CACHE_VISIBILITY=public    # public | private
LLMS_TXT_CACHE_ETAG=false

# Discovery nicety
LLMS_TXT_ADD_LINK_HEADER=false
```

### How main content selection works

[](#how-main-content-selection-works)

By default the package **does not require** a `` tag or any specific HTML wrapper:

- If `main_content_selector` / `LLMS_TXT_MAIN_CONTENT_SELECTOR` is **set and matches elements** (for example the default `'main'` and your layout uses `...`), then **only that matched region** is converted to markdown for the machine view.
- If the selector is **set but matches nothing** on the page, the package simply falls back to converting the **entire HTML response** to markdown.
- If the selector is **`null` or an empty string**, the selector step is skipped and again the **entire HTML response** is converted.

This means:

- Using `` is a **convention, not a requirement**; you can point the selector at any container (`#content`, `.prose`, `[data-llms-main]`, a custom element, etc.).
- The llms.txt **spec only defines the `/llms.txt` index file**; the per‑route machine view is a convenience built on top, and will always return a markdown representation of your HTML (either narrowed to the selector or using the full document).

Testing
-------

[](#testing)

### Running Package Tests

[](#running-package-tests)

```
composer test
```

### Testing in a Laravel Project

[](#testing-in-a-laravel-project)

See [TESTING.md](TESTING.md) for detailed instructions on testing the package in a real Laravel application with SSR routes.

Quick start:

1. Install the package locally using Composer path repository
2. Publish config: `php artisan vendor:publish --tag=llms-txt-config`
3. Create test routes and views
4. Test `/llms.txt`, `/your-route.md`, and `/your-route?view=machine`

Requirements
------------

[](#requirements)

- PHP ^7.2.5|^8.0
- Laravel ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

- Inspired by the [llms.txt specification](https://llmstxt.org/)
- Human/Machine view concept inspired by [parallel.ai](https://parallel.ai/pricing)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance84

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

2

Last Release

82d ago

PHP version history (2 changes)v0.1.0PHP ^8.0

v0.1.1PHP ^7.2.5|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2187404c123a66d5fb7ad905fd226e1a077c2108f973dd3fa280ba2d641e321?d=identicon)[sagarchauhan005](/maintainers/sagarchauhan005)

---

Top Contributors

[![sagarchauhan005](https://avatars.githubusercontent.com/u/7292512?v=4)](https://github.com/sagarchauhan005 "sagarchauhan005 (19 commits)")

---

Tags

laravelaimarkdownAgentllmsllms-txt

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sagarchauhan005-laravel-llms-txt/health.svg)

```
[![Health](https://phpackages.com/badges/sagarchauhan005-laravel-llms-txt/health.svg)](https://phpackages.com/packages/sagarchauhan005-laravel-llms-txt)
```

###  Alternatives

[spatie/laravel-markdown-response

Serve markdown versions of your HTML pages to AI agents and bots

6512.6k](/packages/spatie-laravel-markdown-response)[mischasigtermans/laravel-toon

Token-Optimized Object Notation encoder/decoder for Laravel with intelligent nested object handling

13113.1k](/packages/mischasigtermans-laravel-toon)[dniccum/nova-documentation

A Laravel Nova tool that allows you to add markdown-based documentation to your administrator's dashboard.

37116.4k](/packages/dniccum-nova-documentation)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[xetaio/xetaravel-editor-md

A wrapper to use Editor.md with Laravel.

232.7k](/packages/xetaio-xetaravel-editor-md)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
