laravel-edge-clear maintained by eloquage
Description
Standalone Cloudflare cache purging for Laravel
Author
Eloquage
Last update
2026/11/03 16:07
(dev-main)
License
Downloads
5
Tags
Laravel Edge Clear

Purge Cloudflare cache and set edge-cache headers from a Laravel application.
Requires PHP 8.3+ and Laravel 11, 12, or 13.
Install and configure
composer require eloquage/laravel-edge-clear
php artisan vendor:publish --tag=edge-clear-config
Set your Cloudflare zone and API token in .env:
CLOUDFLARE_ZONE_ID=your-zone-id
CLOUDFLARE_API_TOKEN=your-api-token
Purging is enabled only in production by default. Set
EDGE_CLEAR_ONLY_IN_PRODUCTION=false to enable it in other environments.
Never use real credentials in local or test environments.
Purge cache
use IllumaLaw\EdgeClear\Facades\CloudflarePurger;
CloudflarePurger::purgeByUrls([
'https://example.com/posts/hello',
'https://example.com/posts',
]);
You can also purge by tags or clear the whole zone:
CloudflarePurger::purgeByTags(['posts', 'news']);
CloudflarePurger::purgeEverything();
The SetEdgeCacheHeaders middleware adds cache headers to successful GET
responses. The optional BypassEdgeCache middleware disables caching for a
route:
use IllumaLaw\EdgeClear\Middleware\BypassEdgeCache;
use IllumaLaw\EdgeClear\Middleware\SetEdgeCacheHeaders;
Route::get('/posts', PostsController::class)
->middleware(SetEdgeCacheHeaders::class.':600;posts');
Route::get('/account', AccountController::class)
->middleware(BypassEdgeCache::class);
Test
composer test
composer analyse
vendor/bin/pint --test
MIT licensed. See LICENSE.