Skip to content

Instantly share code, notes, and snippets.

@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;