Skip to content

villaflor/laravel-cloudflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Cloudflare

Cloudflare library for Laravel. This library is an expansion of the official Cloudflare PHP SDK

Requirement

  • Cloudflare API token

Installation

In terminal

composer require villaflor/laravel-cloudflare

php artisan vendor:publish --provider="Villaflor\Cloudflare\CloudflareServiceProvider"

In .env file add this line

CLOUDFLARE_API_TOKEN={API token here}

Methods Available

CloudflareDNS

  • addRecord
  • listRecords
  • getRecordDetails
  • getRecordID
  • updateRecordDetails
  • deleteRecord

CloudflareDNSAnalytics

  • getReportTable
  • getReportByTime

CloudflareIps

  • listIPs

CloudflareZone

  • addZone
  • activationCheck
  • pause
  • unpause
  • getZoneById
  • listZones
  • getZoneID
  • getAnalyticsDashboard
  • changeDevelopmentMode
  • getCachingLevel
  • setCachingLevel
  • cachePurgeEverything
  • cachePurge
  • deleteZone

CloudflareZoneLockdown

  • listLockdowns
  • createLockdown
  • getLockdownDetails
  • updateLockdown
  • deleteLockdown

CloudflareZoneSettings

  • getMinifySetting
  • getRocketLoaderSetting
  • getAlwaysOnlineSetting
  • getEmailObfuscationSetting
  • getServerSideExcludeSetting
  • getHotlinkProtectionSetting
  • getBrowserCacheTtlSetting
  • updateBrowserCacheTtlSetting
  • updateMinifySetting
  • updateRocketLoaderSetting
  • updateAlwaysOnlineSetting
  • updateEmailObfuscationSetting
  • updateHotlinkProtectionSetting
  • updateServerSideExcludeSetting

Usage

This library uses Dependency injection. Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods.

use Villaflor\Cloudflare\CloudflareDNS;

class MyClass
{
    private $cloudflareDNS;

    public function __construct(CloudflareDNS $cloudflareDNS)
    {
        $this->cloudflareDNS = $cloudflareDNS;
    }

    public function UpdateDNS()
    {
        $details = [
            'type' => 'A',
            'name' => 'my-domain.com',
            'content' => '1.2.3.4',
            'ttl' => 1,
            'proxied' => true,
        ];

        return $this->cloudflareDNS->updateRecordDetails('zone-id', 'record-id', $details);
    }
    
    public function DetailDNS()
    {
        return $this->cloudflareDNS->getRecordDetails('zone-id', 'record-id');
    }
    
    public function ListDNS()
    {
        return $this->cloudflareDNS->listRecords('zone-id');
    }
}

About

A Laravel client library for accessing Cloudflare APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages