deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Laravel Snippets runs every Laravel 13 docs example in the browser via PHP.wasm

Laravel Snippets renders the Laravel 13.x documentation so every PHP code block is editable and runnable in-browser, booting PHP 8.5 and a Laravel bundle inside a web worker.

Laravel Snippets runs every Laravel 13 docs example in the browser via PHP.wasm

A project called Laravel Snippets has turned the Laravel 13.x documentation into a static site where every PHP code block can be executed on the spot. According to an introduction published on dev.to by Capsules Codes, PHP 8.5 boots inside a web worker, unpacks a Laravel 13 framework bundle, and runs each documentation example entirely in the browser. No server executes any code.

Every code block gets a Run button

Each fenced PHP block in the documentation is converted into a snippet with a Run button. Output appears directly beneath the code, keeping the colours of dump() and the framework's own error formatting. The first run pays the cost of booting PHP in the worker; every run after that returns immediately.

The author is clear that this is a showcase for what PHP.wasm snippets are capable of, not an official Laravel offering. The framework underneath is real, though: because the worker unzips a Laravel 13 bundle at boot, Illuminate\Support\Collection, dump() and Lang::get() resolve the way they would in an actual project. The bundle also ships a set of models — User, Post, Flight and Order — since the documentation leans on them constantly and an example referencing App\Models\User would otherwise fail to resolve.

Editable where you read

The snippets are not read-only. Code blocks can be edited in place: tweak a value, chain on an extra call, run again, then press reset to restore the version from the documentation. The stated motivation is the round trip readers normally face — you read about groupBy(), form a mental picture of the result, and only find out whether that picture was right after copying the example into a project and running it. Laravel Snippets collapses that loop onto the page itself.

A mirror, not a snapshot

Rather than freezing a copy of the docs, the site tracks upstream. A scheduled workflow mirrors the laravel/docs markdown repository every day, and a second one fetches Laravel's compiled CSS and fonts daily so the pages keep the original typography. Every successful sync republishes the static site on GitHub Pages.

Measuring what actually runs

Once every example is runnable, the project asks the natural follow-up: how many of them actually work? A workflow uses Playwright to load each prerendered page and execute every snippet through the PHP.wasm worker, sorting results into six buckets: ran-ok, ran-with-stderr, ran-exit-nonzero, worker-error, no-output and never-completed. The sweep runs weekly, and again whenever the runtime or the markdown sources change. The resulting report shows overall totals, a per-page rollup, and every single snippet with its input and output.

Roughly two thirds of the snippets execute cleanly. The author warns against reading the remaining third as documentation bugs: the browser has no database, no Stripe credentials, and no Sanctum or Pennant available, and a large share of the code in the documentation — configuration arrays, class bodies without their surrounding class — was never meant to execute in the first place.

There is nothing to install. The project offers a live demo alongside a GitHub repository, and getting started amounts to picking a page in the sidebar and pressing Run.

Why it matters

Runnable documentation is quietly becoming a mark of quality for developer tools, and this pushes the idea further than most: an entire PHP framework, booted client-side, behind every example in an existing manual. Because execution happens in the browser through a web worker, the site stays static and cheap to host while still doing real work. It is also an unusually honest experiment — the weekly report openly publishes a one-third failure rate and explains the causes, which is useful evidence for anyone considering the pattern elsewhere. If the approach holds up, it points at a plausible direction for other framework documentation: treat code samples as programs to run, not text to read.

  • #laravel
  • #php
  • #documentation
  • #webassembly
  • #developer-tools

Related posts