statically.
Building sites

Site search

One line in site.json builds a Pagefind index on every publish: static files, searched in the visitor's browser.

Set "search": true in site.json and every publish runs Pagefind over the built pages, publishing its index and scripts under /pagefind/. It's static files, so it works on any host and in the client's export. It skips the 404 page and pages marked "Hide from search engines".

Mark what's worth searching

So menus and footers don't match every query, mark the main content in your layout. Once any page has data-pagefind-body, pages without it aren't indexed, so put it in the layout every page uses. Leave an element out with data-pagefind-ignore.

views/layout.blade.php
<main data-pagefind-body>@yield('content')</main>

A search page

A search page is an ordinary page whose template loads Pagefind's ready-made interface:

views/search.blade.php
<link rel="stylesheet" href="/pagefind/pagefind-ui.css">
<script src="/pagefind/pagefind-ui.js"></script>
<div id="search"></div>
<script>
    window.addEventListener('DOMContentLoaded', () =>
        new PagefindUI({ element: '#search', showSubResults: true }));
</script>

Style it with its CSS variables (--pagefind-ui-primary, --pagefind-ui-font and so on) in your own CSS.

Search works on the published site. Previews render pages one at a time and have no index, so search finds nothing there.