Skip to content

Instantly share code, notes, and snippets.

@aerni
aerni / zdd-statamic-guide.md
Last active June 8, 2026 16:18
Persisting Statamic Content Writes Across Zero-Downtime Deployments

Persisting Statamic Content Writes Across Zero-Downtime Deployments

The Problem

Zero-downtime deployments swap releases via a symlink. While a new release is being prepared, the old one keeps serving traffic. Any file Statamic writes during that window (content edits, form submissions, asset uploads) lands in the old release's directory.

This often surfaces as a push failure: error: failed to push some refs to '…'. Updates were rejected because the remote contains work that you do not have locally. The old release's local git history is behind origin (the new code has already shipped), yet it's still the place Statamic tries to commit and push from.

Shared paths (a common ZDD feature, called "Shared Paths" in Laravel Forge, "Linked Folders" in Envoyer, equivalents in Ploi and others) fix the data-loss part by storing the runtime-writable directories in one persistent location and symlinking them into each release. But because those paths are now symlinks, Statamic's git automation can't track them

@aerni
aerni / app.js
Created February 16, 2024 16:17
Stacks
import Alpine from 'alpinejs'
import stack from './stack'
window.Alpine = Alpine
Alpine.plugin(stack)
Alpine.start()
@aerni
aerni / LivewireWithStatamicStaticCaching.md
Last active September 4, 2024 18:11
Learn how to use Livewire together with Statamic's static caching

How to use Livewire with Statamic static caching

Since Statamic 3.4.8

As of Statamic 3.4.8, Livewire works with Statamic's Half and Full Measure static caching without any additional configuration. This is due to the concept of replacers, which takes care of replacing Livewire's CSRF token.

Caveats

There is a catch, though. On the first page load, Statamic will cache the first render of the Livewire component. This can be an issue with components that display dynamic content like entries in random order. In this example, the order won't be random on subsequent page loads, but will always show in the order that it was first cached in.

If your component simply shows the latest articles in descending order, and you clear the cache whenever an entry is saved, you don't have to worry about this, though.

@aerni
aerni / LocalValetDriver.php
Created August 18, 2022 21:27 — forked from jasonvarga/LocalValetDriver.php
Valet Driver that supports Statamic 3's static caching
<?php
class LocalValetDriver extends LaravelValetDriver
{
public function frontControllerPath($sitePath, $siteName, $uri)
{
if ($this->isActualFile($staticPath = $this->getStaticPath($sitePath))) {
return $staticPath;
}
@aerni
aerni / MigrateUsersToDatabase.php
Created August 6, 2021 06:13
Migrate User To Database
<?php
namespace App\Console\Commands;
use SplFileInfo;
use App\Models\User;
use Statamic\Facades\YAML;
use Statamic\Facades\Entry;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;