PHPackages                             daikazu/laravel-llm-ready - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. daikazu/laravel-llm-ready

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

daikazu/laravel-llm-ready
=========================

Serve LLM-optimized markdown versions of your Laravel pages by appending .md to any URL.

v1.2.0(3mo ago)275MITPHPPHP ^8.4CI passing

Since Jan 13Pushed 3mo agoCompare

[ Source](https://github.com/daikazu/laravel-llm-ready)[ Packagist](https://packagist.org/packages/daikazu/laravel-llm-ready)[ Docs](https://github.com/daikazu/laravel-llm-ready)[ GitHub Sponsors](https://github.com/Daikazu)[ RSS](/packages/daikazu-laravel-llm-ready/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (18)Versions (6)Used By (0)

  ![Logo for LLM Ready](art/header-light.png)[![Latest Version on Packagist](https://camo.githubusercontent.com/46bf9f2cec34cede3cd4b2fbd3e82116da6ac0dc83c742b2138fac78d02d96b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6461696b617a752f6c61726176656c2d6c6c6d2d72656164792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/daikazu/laravel-llm-ready)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c5a25c2e55e8fa92c2ddad671d28d9e0d4430b102c54a747eda74b480e6d47dc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6461696b617a752f6c61726176656c2d6c6c6d2d72656164792f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/daikazu/laravel-llm-ready/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e3938f5e323fe016bf82f5c1f8cc5e38536f459a424251773c1cab98e4a9b2c1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6461696b617a752f6c61726176656c2d6c6c6d2d72656164792f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/daikazu/laravel-llm-ready/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/6012047edb41086b6a35f00bfd2179bfd7757cc11b26be5576089b3aac000d5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6461696b617a752f6c61726176656c2d6c6c6d2d72656164792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/daikazu/laravel-llm-ready)

Serve LLM-optimized markdown versions of your Laravel pages by appending .md to any URL.
========================================================================================

[](#serve-llm-optimized-markdown-versions-of-your-laravel-pages-by-appending-md-to-any-url)

Purpose
-------

[](#purpose)

Large Language Models (LLMs) like ChatGPT and Claude work much better with clean markdown than parsing HTML. This package automatically converts your Laravel pages to markdown, making your site more accessible to AI crawlers, tools, and users who want to feed your content to LLMs.

Features
--------

[](#features)

- **Automatic Markdown Conversion**: Append `.md` to any URL or use `?format=md`
- **Smart Content Extraction**: Configurable CSS selectors find your main content
- **Table Support**: HTML tables converted to GitHub Flavored Markdown tables
- **Eyebrow Detection**: Automatically detects and formats eyebrow/label text
- **YAML Frontmatter**: Includes title, description, URL, and timestamps
- **Caching**: TTL-based caching with artisan command for manual invalidation
- **llms.txt Endpoint**: Spec-compliant sitemap at `/llms.txt` ([llmstxt.org](https://llmstxt.org))
- **Markdown Discovery**: Automatic `Link` header, `@llmReady` Blade directive, and `llmReadyUrl()` helper
- **Route Exclusions**: Pattern-based exclusions for admin, API, and other routes
- **Redirect Handling**: Automatically follows redirects (e.g., `/blog` -&gt; `/blog/`)
- **Extensible**: Swap the content extractor with your own implementation

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

[](#requirements)

- PHP 8.4+
- Laravel 12.x

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

[](#installation)

```
composer require daikazu/laravel-llm-ready
```

The package will auto-discover and register itself.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag=llm-ready-config
```

### Server Configuration

[](#server-configuration)

Your web server needs to pass `.md` requests to Laravel instead of trying to serve them as static files.

#### Apache

[](#apache)

The default Laravel `.htaccess` should work. Ensure it contains:

```

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

```

#### Nginx

[](#nginx)

Add this to your server block:

```
location ~ \.md$ {
    try_files /index.php?$query_string =404;
    fastcgi_pass unix:/var/run/php/php-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    include fastcgi_params;
}
```

#### Laravel Valet/Herd

[](#laravel-valetherd)

Works out of the box - no configuration needed.

Usage
-----

[](#usage)

### Accessing Markdown Versions

[](#accessing-markdown-versions)

There are three ways to get the markdown version of a page:

```
# Method 1: Append .md extension
https://yoursite.com/about-us.md

# Method 2: Use ?format=md query parameter
https://yoursite.com/?format=md
https://yoursite.com/about-us?format=md

# Method 3: Use index.md for index pages
https://yoursite.com/index.md        # Home page
https://yoursite.com/blog/index.md   # Blog index

```

### llms.txt Endpoint

[](#llmstxt-endpoint)

The `/llms.txt` endpoint follows the [llmstxt.org](https://llmstxt.org) specification, providing LLMs with structured information about your site:

```
https://yoursite.com/llms.txt

```

Example output:

```
# Your Site Name

> A brief description of your site.

All pages on this site are available in markdown format for LLM consumption.
Append `.md` to any URL or add `?format=md` to get the markdown version.

## Documentation

- [Getting Started](https://yoursite.com/docs/getting-started)
- [API Reference](https://yoursite.com/docs/api)

## Pages

- [Home](https://yoursite.com)
- [About](https://yoursite.com/about)
- [Blog](https://yoursite.com/blog)
```

### Markdown Discovery

[](#markdown-discovery)

LLMs and crawlers need a way to discover that a markdown version of a page exists. This package provides three complementary mechanisms:

#### Automatic Link Header

[](#automatic-link-header)

Every HTML response automatically includes a `Link` header pointing to the markdown version:

```
Link: ; rel="alternate"; type="text/markdown"

```

This is enabled by default. Disable it via config or environment variable:

```
LLM_READY_LINK_HEADER=false
```

#### Blade Directive

[](#blade-directive)

Add a `` tag to your templates so crawlers can discover the markdown version via HTML:

```

    @llmReady
    {{-- Outputs:  --}}

```

The directive is opt-in — it only outputs when you use it, and returns an empty string for excluded routes or when the package is disabled.

#### Helper Function

[](#helper-function)

Use `llmReadyUrl()` in programmatic contexts like SEO middleware (e.g., `romanzipp/laravel-seo`):

```
// Returns "https://yoursite.com/about.md" or null if excluded/disabled
$markdownUrl = llmReadyUrl();
```

### Clear Cache

[](#clear-cache)

```
# Clear all LLM Ready caches
php artisan llm-ready:clear-cache

# Clear cache for a specific URL
php artisan llm-ready:clear-cache --url=https://yoursite.com/about-us

# Clear only the sitemap cache
php artisan llm-ready:clear-cache --sitemap
```

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

[](#configuration)

```
// config/llm-ready.php

return [
    // Enable/disable the package
    'enabled' => env('LLM_READY_ENABLED', true),

    // Cache settings
    'cache' => [
        'enabled' => env('LLM_READY_CACHE_ENABLED', true),
        'ttl' => env('LLM_READY_CACHE_TTL', 1440), // 24 hours in minutes
        'prefix' => 'llm_ready',
    ],

    // CSS selectors to find main content (tried in order)
    'content_selectors' => [
        'main',
        'article',
        '[role="main"]',
        '.content',
    ],

    // Elements to remove before conversion
    'ignore_selectors' => [
        'nav',
        'header',
        'footer',
        'aside',
        '.sidebar',
        'script',
        'style',
    ],

    // Eyebrow/label text detection
    'eyebrow_selectors' => [
        '.eyebrow',
        '.overline',
        '.kicker',
        '[class*="eyebrow"]',
    ],
    'eyebrow_auto_detect' => true,

    // Routes to exclude from markdown conversion (supports nested paths)
    'exclude_patterns' => [
        '/admin/*',    // Matches /admin/users, /admin/settings/email, etc.
        '/api/*',      // Matches /api/v1/users, /api/webhooks/stripe, etc.
        '/livewire/*',
    ],

    // Markdown discovery settings
    'discovery' => [
        'link_header' => env('LLM_READY_LINK_HEADER', true),
    ],

    // llms.txt configuration (follows llmstxt.org spec)
    'llms_txt' => [
        'enabled' => true,
        'cache_ttl' => 60,
        'title' => env('LLM_READY_LLMS_TXT_TITLE'), // Defaults to app name
        'summary' => env('LLM_READY_LLMS_TXT_SUMMARY'),
        'description' => [],
        'sections' => [
            // 'Documentation' => [
            //     ['url' => '/docs/intro.md', 'description' => 'Introduction'],
            // ],
        ],
        'auto_section' => [
            'enabled' => true,
            'title' => 'Pages',
        ],
    ],

    // YAML frontmatter settings
    'frontmatter' => [
        'include_title' => true,
        'include_description' => true,
        'include_url' => true,
        'include_last_modified' => true,
    ],

    // Custom content extractor class
    'extractor' => \Daikazu\LaravelLlmReady\Extractors\DefaultContentExtractor::class,
];
```

Output Example
--------------

[](#output-example)

Requesting `/about-us.md` produces clean markdown:

```
---
title: About Us - Your Company Name
description: Learn about our mission and team
url: https://yoursite.com/about-us
last_modified: 2024-01-15T10:30:00+00:00
---

# About Us

Welcome to our company! We're dedicated to...

## Our Mission

We believe in creating value for our customers through...

## Our Team

| Name | Role | Experience |
|------|------|------------|
| Jane Doe | CEO | 15 years |
| John Smith | CTO | 12 years |
```

Configuring llms.txt
--------------------

[](#configuring-llmstxt)

The llms.txt endpoint can be fully customized to provide curated information to LLMs:

```
'llms_txt' => [
    'title' => 'Acme Documentation',
    'summary' => 'Complete documentation for the Acme platform.',
    'description' => [
        'Acme helps developers build better applications faster.',
        'Our documentation covers installation, configuration, and advanced usage.',
    ],
    'sections' => [
        'Getting Started' => [
            ['url' => '/docs/installation', 'description' => 'How to install Acme'],
            ['url' => '/docs/quickstart', 'description' => '5-minute quickstart guide'],
        ],
        'API Reference' => [
            ['url' => '/docs/api/authentication', 'description' => 'Authentication methods'],
            ['url' => '/docs/api/endpoints', 'description' => 'Available API endpoints'],
        ],
    ],
    'auto_section' => [
        'enabled' => true,
        'title' => 'All Pages',
        'include_in_optional' => false,
    ],
],
```

Custom Content Extractor
------------------------

[](#custom-content-extractor)

Create your own extractor by implementing `ContentExtractorInterface`:

```
