PHPackages                             secretwebmaster/laravel-cloudflare - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. secretwebmaster/laravel-cloudflare

ActiveLibrary[API Development](/categories/api)

secretwebmaster/laravel-cloudflare
==================================

Modern PHP 8+ package for seamless Cloudflare API integration in Laravel applications. Manage zones, DNS records, firewall rules, and more.

v1.0.2(5mo ago)01MITPHPPHP ^8.0

Since Jan 18Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/secretwebmaster/laravel-cloudflare)[ Packagist](https://packagist.org/packages/secretwebmaster/laravel-cloudflare)[ RSS](/packages/secretwebmaster-laravel-cloudflare/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (4)Used By (0)

Laravel Cloudflare
==================

[](#laravel-cloudflare)

A modern PHP 8+ package for seamless Cloudflare API integration in Laravel applications. Manage zones, DNS records, firewall rules, analytics, and more with a clean, type-safe interface.

[![PHP Version](https://camo.githubusercontent.com/d4b5fa4adf514144779a7864904c5e15236c0e798635240c7f6ce9a455657b80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d626c75652e737667)](https://php.net)[![Laravel](https://camo.githubusercontent.com/9530f0d90478e0b25d5bf5abd6ceb7a17377c3c89704a33f3250b5da82065e59/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382532422d7265642e737667)](https://laravel.com)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Features
--------

[](#features)

- **Modern PHP 8+** - Strict type hints, typed properties, and modern syntax
- **Comprehensive Coverage** - Zones, DNS, Firewall, Settings, and more
- **Well Documented** - Extensive PHPDoc **blocks** with parameter tables
- **Type Safe** - Full type safety with strict typing throughout
- **Laravel Integration** - Built specifically for Laravel using HTTP facade
- **Easy to Use** - Intuitive API with consistent method naming
- **Free Tier Friendly** - All free tier functions fully supported
- **Auto-Discovery** - Automatic service provider registration

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 8.0 or higher
- Cloudflare API Token or API Key

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require secretwebmaster/laravel-cloudflare
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=cloudflare-config
```

Add your Cloudflare credentials to your `.env` file:

```
CLOUDFLARE_API_TOKEN=your-api-token
```

Basic Usage
-----------

[](#basic-usage)

### Initialize the Client

[](#initialize-the-client)

```
use Secretwebmaster\LaravelCloudflare\Client;

// Option 1: Create using .env values
$client = new Client();

// Option 2: Create manually with API Token
$client = new Client('your-api-token');

// Option 3: Create manually with Email + API Key
$client = new Client(null, 'your-email@example.com', 'your-api-key');
```

### Working with Zones

[](#working-with-zones)

The `Zones` model provides complete zone management functionality.

#### List All Zones

[](#list-all-zones)

```
// List all zones
$response = $client->zones()->list();

// List zones with pagination
$zones = $client->zones()->list([
    'page' => 1,
    'per_page' => 20
]);

// Filter zones by status
$zones = $client->zones()->list([
    'status' => 'active'
]);
```

#### Get Zone by Domain

[](#get-zone-by-domain)

```
// Get zone information by domain name
$zone = $client->zones()->getByDomain('example.com');
```

#### Get Zone ID by Domain

[](#get-zone-id-by-domain)

```
// Quickly get just the zone ID
$zoneId = $client->zones()->getZoneIdByDomain('example.com');
```

#### Create a New Zone

[](#create-a-new-zone)

```
$response = $client->zones()->create([
    'name' => 'example.com',
]);
```

#### Get Zone Details

[](#get-zone-details)

```
$response = $client->zones()->get($zoneId);
```

#### Update Zone Settings

[](#update-zone-settings)

```
$client->zones()->edit($zoneId, [
    'paused' => false,
    'plan' => [
        'id' => 'plan-id'
    ]
]);
```

#### Purge Cache

[](#purge-cache)

```
// Purge everything
$client->zones()->purgeCache($zoneId, ['purge_everything' => true]);

// Purge specific files
$client->zones()->purgeCache($zoneId, [
    'files' => [
        'https://example.com/style.css',
        'https://example.com/script.js'
    ]
]);

// Purge by tags
$client->zones()->purgeCache($zoneId, [
    'tags' => ['static', 'images']
]);

// Purge by hostname
$client->zones()->purgeCache($zoneId, [
    'hosts' => ['www.example.com', 'api.example.com']
]);
```

#### Check Zone Activation

[](#check-zone-activation)

```
$response = $client->zones()->activationCheck($zoneId);
```

#### Delete Zone

[](#delete-zone)

```
$response = $client->zones()->delete($zoneId);
```

### Working with DNS Records

[](#working-with-dns-records)

The `DnsRecords` model handles all DNS record operations.

#### List DNS Records

[](#list-dns-records)

```
// List all DNS records for a zone
$response = $client->dnsRecords()->list($zoneId);

// Filter by record type
$records = $client->dnsRecords()->list($zoneId, [
    'type' => 'A'
]);

// Filter by name
$records = $client->dnsRecords()->list($zoneId, [
    'name' => 'www.example.com'
]);

// Combine filters with pagination
$records = $client->dnsRecords()->list($zoneId, [
    'type' => 'A',
    'page' => 1,
    'per_page' => 50
]);
```

#### Create DNS Record

[](#create-dns-record)

```
// Create an A record
$record = $client->dnsRecords()->create($zoneId, [
    'type' => 'A',
    'name' => 'www.example.com',
    'content' => '192.168.1.1',
    'ttl' => 1,  // 1 = Auto
    'proxied' => true
]);

// Create a CNAME record
$record = $client->dnsRecords()->create($zoneId, [
    'type' => 'CNAME',
    'name' => 'blog',
    'content' => 'example.com',
    'ttl' => 1,
    'proxied' => false
]);

// Create an MX record
$record = $client->dnsRecords()->create($zoneId, [
    'type' => 'MX',
    'name' => 'example.com',
    'content' => 'mail.example.com',
    'priority' => 10,
    'ttl' => 1
]);

// Create a TXT record
$record = $client->dnsRecords()->create($zoneId, [
    'type' => 'TXT',
    'name' => '_dmarc',
    'content' => 'v=DMARC1; p=reject; rua=mailto:admin@example.com',
    'ttl' => 1
]);
```

#### Get DNS Record Details

[](#get-dns-record-details)

```
$response = $client->dnsRecords()->get($zoneId, $recordId);
```

#### Update DNS Record (Full Update)

[](#update-dns-record-full-update)

```
// Update entire record
$client->dnsRecords()->update($zoneId, $recordId, [
    'type' => 'A',
    'name' => 'www.example.com',
    'content' => '192.168.1.2',
    'ttl' => 1,
    'proxied' => true
]);
```

#### Patch DNS Record (Partial Update)

[](#patch-dns-record-partial-update)

```
// Update only specific fields
$client->dnsRecords()->edit($zoneId, $recordId, [
    'content' => '192.168.1.3',
    'proxied' => false
]);

// Just change TTL
$client->dnsRecords()->edit($zoneId, $recordId, [
    'ttl' => 3600
]);
```

#### Delete DNS Record

[](#delete-dns-record)

```
$response = $client->dnsRecords()->delete($zoneId, $recordId);
```

Advanced Usage
--------------

[](#advanced-usage)

### Zone Settings

[](#zone-settings)

Manage all zone settings with dedicated getter and setter methods.

```
// Get SSL setting
$response = $client->zoneSettings()->getSsl($zoneId);

// Update SSL setting
$client->zoneSettings()->updateSsl($zoneId, ['value' => 'full']);

// Get Always Use HTTPS
$alwaysHttps = $client->zoneSettings()->getAlwaysUseHttps($zoneId);

// Enable Always Use HTTPS
$client->zoneSettings()->updateAlwaysUseHttps($zoneId, ['value' => 'on']);

// Get and update multiple settings
$settings = $client->zoneSettings()->list($zoneId);

// Update any setting using the generic update method
$client->zoneSettings()->update($zoneId, 'minify', [
    'value' => [
        'css' => 'on',
        'html' => 'on',
        'js' => 'on'
    ]
]);
```

### Firewall Access Rules

[](#firewall-access-rules)

Manage IP access rules at zone, account, or user level.

```
// Zone-level: Block an IP
$client->firewallAccessRules()->create($zoneId, [
    'mode' => 'block',
    'configuration' => [
        'target' => 'ip',
        'value' => '192.168.1.100'
    ],
    'notes' => 'Blocked spam source'
]);

// Zone-level: Whitelist an IP range
$client->firewallAccessRules()->create($zoneId, [
    'mode' => 'whitelist',
    'configuration' => [
        'target' => 'ip_range',
        'value' => '10.0.0.0/8'
    ],
    'notes' => 'Office IP range'
]);

// Account-level: Challenge by country
$client->firewallAccessRules()->createAccount($accountId, [
    'mode' => 'challenge',
    'configuration' => [
        'target' => 'country',
        'value' => 'CN'
    ]
]);

// List zone access rules
$rules = $client->firewallAccessRules()->list($zoneId);

// Delete a rule
$client->firewallAccessRules()->delete($zoneId, $ruleId);
```

### Page Rules

[](#page-rules)

Create and manage page rules for URL-specific behaviors.

```
// Create a page rule
$client->pageRules()->create($zoneId, [
    'targets' => [
        [
            'target' => 'url',
            'constraint' => [
                'operator' => 'matches',
                'value' => 'example.com/admin/*'
            ]
        ]
    ],
    'actions' => [
        [
            'id' => 'ssl',
            'value' => 'strict'
        ],
        [
            'id' => 'always_use_https',
            'value' => true
        ]
    ],
    'priority' => 1,
    'status' => 'active'
]);

// List all page rules
$rules = $client->pageRules()->list($zoneId);

// Get available settings
$settings = $client->pageRules()->getSettingList();
```

### Accounts &amp; Users

[](#accounts--users)

```
// List accounts
$accounts = $client->accounts()->list();

// Get account details
$account = $client->accounts()->get($accountId);

// Get user details
$user = $client->users()->get();

// Update user
$client->users()->update([
    'first_name' => 'John',
    'last_name' => 'Doe'
]);
```

Available Models
----------------

[](#available-models)

All models are accessible through the client:

ModelDescriptionMethods`Zones`Zone managementlist, create, get, edit, delete, purgeCache, etc.`DnsRecords`DNS record managementlist, create, get, update, patch, delete, import, export`ZoneSettings`Zone settings (86 methods)getSsl, updateSsl, getMinify, updateMinify, etc.`FirewallAccessRules`IP access rulesUser/Account/Zone level CRUD operations`FirewallLockdowns`Zone lockdown ruleslist, create, get, update, delete`FirewallUARules`User Agent blockinglist, create, get, update, delete`Waf`Web Application FirewallOverrides, Packages, Groups, Rules management`PageRules`Page ruleslist, create, get, update, delete`Accounts`Account managementlist, get, details, update`Users`User managementget, details, updateError Handling
--------------

[](#error-handling)

All methods return the Cloudflare API response. Check the `success` field:

```
$response = $client->zones()->create(['name' => 'example.com']);

// Get error code explanations
$errorCodes = $client->zones()->errorCodes();
echo $errorCodes['1061']; // "An A, AAAA or CNAME record already exists..."
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for recent changes.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Security
--------

[](#security)

If you discover any security-related issues, please email the package maintainer instead of using the issue tracker.

Credits
-------

[](#credits)

- **Author**: SecretWebmaster
- Built with ❤️ for the Laravel community

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Resources
---------

[](#resources)

- [Cloudflare API Documentation](https://developers.cloudflare.com/api/)
- [Laravel Documentation](https://laravel.com/docs)
- [Package Repository](https://github.com/secretwebmaster/laravel-cloudflare)

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/secretwebmaster/laravel-cloudflare/issues)
- **Documentation**: This README and inline PHPDoc blocks
- **Cloudflare API**: [Official API Docs](https://developers.cloudflare.com/api/)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance72

Regular maintenance activity

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

161d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16463637?v=4)[secretwebmaster](/maintainers/secretwebmaster)[@secretwebmaster](https://github.com/secretwebmaster)

---

Top Contributors

[![secretwebmaster](https://avatars.githubusercontent.com/u/16463637?v=4)](https://github.com/secretwebmaster "secretwebmaster (13 commits)")

---

Tags

apilaraveldnscloudflarefirewallzonesCloudFlare APIcloudflare-dns

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/secretwebmaster-laravel-cloudflare/health.svg)

```
[![Health](https://phpackages.com/badges/secretwebmaster-laravel-cloudflare/health.svg)](https://phpackages.com/packages/secretwebmaster-laravel-cloudflare)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

3.0k37.6M134](/packages/darkaonline-l5-swagger)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k14.2M63](/packages/knuckleswtf-scribe)[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k9.5M89](/packages/openai-php-laravel)[statamic/cms

The Statamic CMS Core Package

4.8k3.6M984](/packages/statamic-cms)[aimeos/aimeos-laravel

Cloud native, API first Laravel eCommerce package with integrated AI for ultra-fast online shops, marketplaces and complex B2B projects

8.7k225.1k5](/packages/aimeos-aimeos-laravel)[cloudcreativity/laravel-json-api

JSON API (jsonapi.org) support for Laravel applications.

7851.1M5](/packages/cloudcreativity-laravel-json-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
