Documentation v1.0.0
Overview
The Laravel Cloudflare SDK provides a premium client interface for managing domain zones, DNS settings, Worker scripts, KV stores, D1 Databases, and R2 buckets. Compatible with PHP 8.2 through 8.5, and Laravel 11 through 13.
Installation
Install the package through Composer:
composer require ghostcompiler/laravel-cloudflare
Publish the configuration assets:
php artisan vendor:publish --provider="Vendor\Cloudflare\Providers\CloudflareServiceProvider" --tag="config"
Configuration
The configuration file is published at config/cloudflare.php. You can generate your API Token from the Cloudflare Dashboard.
return [
'token' => env('CLOUDFLARE_TOKEN'),
'email' => env('CLOUDFLARE_EMAIL'),
'api_key' => env('CLOUDFLARE_API_KEY'),
'base_url' => env('CLOUDFLARE_BASE_URL', 'https://api.cloudflare.com/client/v4'),
'timeout' => (int) env('CLOUDFLARE_TIMEOUT', 30),
'retries' => (int) env('CLOUDFLARE_RETRIES', 3),
];
Accounts
List and manage Cloudflare account profiles, member roles, and permissions.
// List accounts
$accounts = Cloudflare::accounts()->all();
// Find account by ID
$account = Cloudflare::accounts()->find('account_id');
Zones
Manage domain zones, trigger activation checks, and control caching configurations.
// List zones
$zones = Cloudflare::zones()->all();
// Create new zone
$zone = Cloudflare::zones()->create([
'name' => 'example.com',
'account' => ['id' => 'account_id']
]);
Zone Settings
Manage advanced settings of a zone like SSL mode, security level, and minification.
// Get all settings for a zone
$settings = Cloudflare::zoneSettings()->all($zoneId);
// Update specific setting
Cloudflare::zoneSettings()->update($zoneId, 'security_level', ['value' => 'high']);
DNS Records
Provision and manage A, AAAA, CNAME, MX, and TXT records within a zone.
// List DNS records
$records = Cloudflare::dns()->all($zoneId);
// Create DNS Record
$record = Cloudflare::dns()->create($zoneId, [
'type' => 'A',
'name' => 'www',
'content' => '1.2.3.4',
'proxied' => true
]);
SSL Certificates
Upload and manage custom SSL certificates for custom domains.
// List custom certificates
$certs = Cloudflare::sslCertificates()->all($zoneId);
Certificate Packs
Manage advanced SSL/TLS certificate packs ordered for the zone.
// List certificate packs
$packs = Cloudflare::certificatePacks()->all($zoneId);
Custom Hostnames
Configure custom hostnames (SaaS applications) under your zone.
// List custom hostnames
$hostnames = Cloudflare::customHostnames()->all($zoneId);
Firewall Rules
Configure custom IP firewall, user-agent blocking, and security rules.
// List firewall rules
$rules = Cloudflare::firewallRules()->all($zoneId);
Rulesets
Create and modify Rulesets for WAF (Web Application Firewall) at account or zone level.
// List zone rulesets
$rulesets = Cloudflare::rulesets()->all($zoneId, false);
Page Rules
Set caching behaviors, URL forwarding, and custom headers based on URL patterns.
// List page rules
$rules = Cloudflare::pageRules()->all($zoneId);
Cache Purge
Purge files, tags, hosts, or prefixes from Cloudflare edge caches.
// Purge everything
Cloudflare::cache()->purgeAll($zoneId);
// Purge specific files
Cloudflare::cache()->purgeFiles($zoneId, ['https://example.com/main.css']);
Load Balancers
Deploy custom HTTP load balancers under your zone.
// List load balancers
$lbs = Cloudflare::loadBalancers()->all($zoneId);
Load Balancer Pools
Configure origin server pools for your global load balancers.
// List LB Pools
$pools = Cloudflare::loadBalancerPools()->all($accountId);
Load Balancer Monitors
Configure active health monitors checking origin server availability.
// List LB Monitors
$monitors = Cloudflare::loadBalancerMonitors()->all($accountId);
Workers
Deploy serverless JavaScript/TypeScript Worker scripts onto Cloudflare edge servers.
// List Worker scripts
$scripts = Cloudflare::workers()->all($accountId);
Worker Routes
Map custom URL patterns to Worker script execution namespaces.
// List Worker routes
$routes = Cloudflare::workerRoutes()->all($zoneId);
KV Storage
Read, write, and list low-latency key-value pairs globally.
// Write value
Cloudflare::kv()->putValue($accountId, $namespaceId, 'key', 'value');
// Read value
$value = Cloudflare::kv()->getValue($accountId, $namespaceId, 'key');
R2 Storage
Zero egress-fee object storage bucket provisioning and management.
// List buckets
$buckets = Cloudflare::r2()->all($accountId);
D1 Databases
Serverless SQL databases at the edge built on SQLite.
// Run SQL query
$result = Cloudflare::d1()->query($accountId, $databaseId, 'SELECT * FROM users');
Pages Projects
Create and deploy Jamstack web sites and fullstack applications.
// List Pages projects
$projects = Cloudflare::pages()->all($accountId);
Cloudflare Images
Upload, crop, resize, and deliver high-performance images.
// List images
$images = Cloudflare::images()->all($accountId);
Cloudflare Stream
Upload, encode, storage, and deliver video content at scale.
// List stream videos
$videos = Cloudflare::stream()->all($accountId);
Email Routing
Configure catch-all routing rules and forwarding destinations for domain emails.
// Get settings
$settings = Cloudflare::emailRouting()->getSettings($zoneId);
Access Applications
Secure internal applications using Cloudflare Access policy constraints.
// List Access apps
$apps = Cloudflare::access()->all($accountId);
Cloudflare Tunnels
Connect local web server origins securely without public IP openings.
// List tunnels
$tunnels = Cloudflare::tunnels()->all($accountId);
Turnstile widgets
Zero-friction user CAPTCHA challenge replacement widgets.
// List Turnstile widgets
$widgets = Cloudflare::turnstile()->all($accountId);
Healthchecks
Set up health monitoring checks for domain origin paths.
// List healthchecks
$checks = Cloudflare::healthchecks()->all($zoneId);
Waiting Rooms
Deploy custom virtual queues to manage high-traffic spikes under your zone.
// List waiting rooms
$rooms = Cloudflare::waitingRooms()->all($zoneId);
Logpush Jobs
Configure automated high-speed log output exporting to S3, Datadog, or storage buckets.
// List logpush jobs
$jobs = Cloudflare::logpush()->all($zoneId);
User Profile
Manage current Cloudflare user profile settings and API tokens.
// Get user profile
$user = Cloudflare::user()->get();