Currently Available: Need a skilled Software Developer for your next project?
Categories
Laravel

Render Markdown Documentation in Laravel with pxlrbt/laravel-docs

Laravel developers who keep help pages in Markdown can use pxlrbt/laravel-docs to serve those files as a documentation section inside their app. The package reads Markdown from a configured directory, registers routes, builds page navigation, and renders a layout so readers can browse the docs directly on your site.

You install the package with Composer, publish its configuration and assets, and write pages with YAML frontmatter (a short block of metadata at the top of a Markdown file). You can also set up separate documentation areas and require authentication for private pages. The package’s README covers the setup and available options.

Install the package and add a page

Start by adding the package and publishing its files from your Laravel project directory:

composer require pxlrbt/laravel-docs

php artisan vendor:publish --tag=docs-config
php artisan vendor:publish --tag=docs-assets

Composer installs the package, and the Artisan commands copy its configuration file and assets into your app. By default, the package reads pages from docs/ and serves them under the docs URL prefix.

Next, add a Markdown file in that directory. For example, you can create docs/getting-started.md:

---
title: "Getting Started"
description: "An introduction to the app"
group: "Basics"
order: 0
---

# Getting Started

Add your setup instructions here.

The package reads the frontmatter to label and organize the page, then renders the text below it as the page content. It builds each route from the URL prefix and the page slug (the short name used in the URL). Because the package documentation does not spell out every slug-generation rule, check the route in your app instead of assuming how the package handles filenames with spaces or punctuation.

Organize pages for readers

As your documentation grows, you can use the group and order fields in your frontmatter to arrange pages in the sidebar. The package generates a table of contents from H2 and H3 headings, adds links to headings, and includes previous- and next-page navigation. Readers can move through a folder of Markdown files like a structured guide instead of hunting through unrelated pages.

The GitHub README also lists GitHub-flavored Markdown and responsive styling, along with sidebar caching and directory-traversal protection. On top of that, the Packagist package page lists extra rendering features such as Mermaid diagrams, image captions, image and video lightboxes, and accordions built with <details> and <summary>.

If you plan to use those features, test them with the Markdown you intend to publish. The available documentation does not fully explain details like raw HTML handling, relative image paths, or how the sidebar cache refreshes after you edit a file.

Set a layout and separate documentation areas

In config/docs.php, you can point the package to a Blade layout (a reusable page template written in Laravel’s Blade templating language) to wrap your rendered pages. If you leave that setting out, the package serves a standalone page with its own styles. You can keep the standalone view to get up and running quickly, or wrap the pages in your own Blade layout when you want the docs to share your app’s navigation and branding.

The configuration also supports multiple named documentation areas, each with its own directory and URL prefix. For example, your app can serve general pages from docs/ and API documentation from docs/api:

return [
    'default' => [
        'root' => 'docs',
        'url_prefix' => 'docs',
    ],

    'api' => [
        'root' => 'docs/api',
        'url_prefix' => 'api-docs',
        'requires_auth' => true,
        'auth_middleware' => ['auth'],
    ],
];

That keeps the files and routes for each documentation area separate. For related guidance on organizing access, see separating public and internal documentation.

Protect private documentation explicitly

By default, pxlrbt/laravel-docs leaves documentation open to everyone because it treats authentication as optional and sets requires_auth to false. To lock down private docs, set requires_auth to true and attach authentication middleware or an access callback. You can use middleware to require a signed-in user, or write a callback to enforce a stricter rule, such as allowing only administrators.

Once you update those settings, test the documentation routes while signed out and again while signed in as a user who should not have access. The package lists directory-traversal protection as a feature, which blocks attempts to read files outside the documentation directory, but it does not restrict who can view private pages. Because the documentation does not include an independent security audit or detailed implementation guarantees, verify the access behavior in your own app.

Check Laravel compatibility before installing

Before you install the package, check whether it supports your version of Laravel. Right now, the Packagist metadata and the repository README disagree on which Laravel versions are supported.

Compare the package’s current Composer constraints against your project’s Laravel version. When you run Composer, it checks those constraints and reports a dependency conflict if the package requirements do not fit your setup.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *