PHP code example of illuma-law / laravel-edge-clear
1. Go to this page and download the library: Download illuma-law/laravel-edge-clear library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
illuma-law / laravel-edge-clear example snippets
return [
'zone_id' => env('CLOUDFLARE_ZONE_ID'),
// Auth method 1 (Preferred)
'api_token' => env('CLOUDFLARE_API_TOKEN'),
// Auth method 2
'api_email' => env('CLOUDFLARE_API_EMAIL'),
'api_key' => env('CLOUDFLARE_API_KEY'),
// Toggle the service globally
'enabled' => env('CLOUDFLARE_ENABLED', true),
// Prevent accidental API calls in local dev
'only_in_production' => env('CLOUDFLARE_ONLY_IN_PRODUCTION', true),
// Enable detailed API request logging
'debug' => env('CLOUDFLARE_DEBUG', false),
];
use IllumaLaw\EdgeClear\Facades\CloudflarePurger;
// Purge specific URLs (Useful in Model Observers)
CloudflarePurger::purgeByUrls([
'https://example.com/blog/my-updated-post',
'https://example.com/blog',
]);
// Purge by cache tags (Requires Cloudflare Enterprise)
CloudflarePurger::purgeByTags(['tag:blog', 'tag:news']);
// Purge the entire zone cache (Useful after deploying huge site changes)
CloudflarePurger::purgeEverything();
namespace App\Observers;
use App\Models\Post;
use IllumaLaw\EdgeClear\Facades\CloudflarePurger;
class PostObserver
{
public function saved(Post $post): void
{
// Purge the specific post and the blog index
CloudflarePurger::purgeByUrls([
url("/blog/{$post->slug}"),
url('/blog'),
]);
}
}
use IllumaLaw\EdgeClear\Middleware\BypassEdgeCache;
Route::get('/admin/dashboard', [DashboardController::class, 'index'])
->middleware(BypassEdgeCache::class);
use IllumaLaw\EdgeClear\Middleware\SetEdgeCacheHeaders;
Route::get('/public-news', [NewsController::class, 'index'])
->middleware(SetEdgeCacheHeaders::class.':600;tag:news;short');
use IllumaLaw\EdgeClear\Jobs\PurgeEdgeCacheJob;
PurgeEdgeCacheJob::dispatch(
tags: ['tag:blog'],
urls: ['https://example.com/blog'],
reason: 'blog_updated'
);