PHPackages                             suitmedia/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. [Caching](/categories/caching)
4. /
5. suitmedia/laravel-cloudflare

ActiveLibrary[Caching](/categories/caching)

suitmedia/laravel-cloudflare
============================

Simple and easy cloudflare cache purging in Laravel

1.2.0(2y ago)99.2k↓33.3%4[1 PRs](https://github.com/suitmedia/laravel-cloudflare/pulls)MITPHPPHP ^7.4|^8.0

Since Mar 23Pushed 2y ago4 watchersCompare

[ Source](https://github.com/suitmedia/laravel-cloudflare)[ Packagist](https://packagist.org/packages/suitmedia/laravel-cloudflare)[ Docs](https://github.com/suitmedia/laravel-cloudflare)[ RSS](/packages/suitmedia-laravel-cloudflare/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (4)Used By (0)

[![Build Status](https://github.com/suitmedia/laravel-cloudflare/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/suitmedia/laravel-cloudflare/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/5a6b60a016a82ad1efa885071c857b17e171cb4dbc3fff5b8a82fdab3202b008/68747470733a2f2f636f6465636f762e696f2f67682f737569746d656469612f6c61726176656c2d636c6f7564666c6172652f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d35454b33434c36535945)](https://codecov.io/gh/suitmedia/laravel-cloudflare)[![Total Downloads](https://camo.githubusercontent.com/1d362e4273c8e5acb64b1450cd132dd1d514893a9bc060be3fc84eac3d84eebd/68747470733a2f2f706f7365722e707567782e6f72672f737569746d656469612f6c61726176656c2d636c6f7564666c6172652f642f746f74616c2e737667)](https://packagist.org/packages/suitmedia/laravel-cloudflare)[![Latest Stable Version](https://camo.githubusercontent.com/2e606bdb1d9b9d644eb7099c8b8c420a200261fc58fc4dc22a9fa252366f70e6/68747470733a2f2f706f7365722e707567782e6f72672f737569746d656469612f6c61726176656c2d636c6f7564666c6172652f762f737461626c652e737667)](https://packagist.org/packages/suitmedia/laravel-cloudflare)[![License: MIT](https://camo.githubusercontent.com/f4f6c31aa7a04b9f5e777bfda0d14b44380129199bac160bd238aaecbd699663/68747470733a2f2f706f7365722e707567782e6f72672f737569746d656469612f6c61726176656c2d636c6f7564666c6172652f6c6963656e73652e737667)](https://opensource.org/licenses/MIT)

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

[](#laravel-cloudflare)

> Purge Cloudflare Cache on Model Update

Synopsis
--------

[](#synopsis)

This package offers easy ways to purge Cloudflare Cache on Model update.

Table of contents
-----------------

[](#table-of-contents)

- [Setup](#setup)
- [Publish package assets](#publish-package-assets)
- [Configuration](#configuration)
- [Usage](#usage)
- [Credits](#credits)
- [License](#license)

Setup
-----

[](#setup)

Install the package via Composer :

```
$ composer require suitmedia/laravel-cloudflare
```

### Laravel version compatibility

[](#laravel-version-compatibility)

Laravel versionLaravel Cloudflare version8.x1.x### Service Provider

[](#service-provider)

Add the package service provider in your `config/app.php`

```
'providers' => [
    // ...
    Suitmedia\Cloudflare\ServiceProvider::class,
];
```

### Alias

[](#alias)

Add the package's alias in your `config/app.php`

```
'aliases' => [
    // ...
    'CloudflareCache' => Suitmedia\Cloudflare\Facade::class,
];
```

Publish package assets
----------------------

[](#publish-package-assets)

Publish the package asset files using this `php artisan` command

```
$ php artisan vendor:publish --provider="Suitmedia\Cloudflare\ServiceProvider"
```

The command above would create new `laravel-cloudflare.php` file in your application's config directory.

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

[](#configuration)

```
return [

    /*
    |--------------------------------------------------------------------------
    | Cloudflare Site
    |--------------------------------------------------------------------------
    |
    | Specify the sitename of the Cloudflare.
    |
    */
    'sitename' => env('CLOUDFLARE_SITE', 'test.com'),

    /*
    |--------------------------------------------------------------------------
    | Cloudflare Authentication Email
    |--------------------------------------------------------------------------
    |
    | Specify the authentication email to access Cloudflare.
    |
    */
    'auth_email' => env('CLOUDFLARE_AUTH_EMAIL', 'example@domain.com'),

    /*
    |--------------------------------------------------------------------------
    | Cloudflare Authentication Key
    |--------------------------------------------------------------------------
    |
    | Specify the authentication key to access Cloudflare.
    |
    */
    'auth_key' => env('CLOUDFLARE_AUTH_KEY', 'test_auth_key'),
];
```

Usage
-----

[](#usage)

This package assumes that the Page Rules has configured in your Cloudflare Dashboard. To configure the Page Rules, please refer to the [Page Rules Tutorial](https://support.cloudflare.com/hc/en-us/articles/218411427-Understanding-and-Configuring-Cloudflare-Page-Rules-Page-Rules-Tutorial-).

Depends on the way the Page Rules configured, Cloudflare will cache each page in our website for some time. The Cloudflare will then serve the page from its cache, and will not send the request to the application server. This become a problem when there are data updates from the server. Because Cloudflare does not know when the data is updated, so it still serve the outdated data to the user. We need to purge the cache stored in Cloudflare.

Cloudflare provide [API endpoints](https://api.cloudflare.com/#zone-purge-all-files) to purge its cache programmatically. This package utilize those API endpoints to purge the cache on model updates.

To start using this package, you need to add these credentials to the `.env` file:

```
CLOUDFLARE_SITE=registered-cloudflare-sitename.com
CLOUDFLARE_AUTH_EMAIL=cloudflare-account@email.com
CLOUDFLARE_AUTH_KEY=cloudflare-auth-key

```

You can find the Cloudflare Auth Key in the [API Tokens](https://dash.cloudflare.com/profile/api-tokens) section on the profile page in your Cloudflare account. Copy the value of the Global API Key to your .env file.

Add the `Suitmedia\Cloudflare\Model\Concerns\Cloudflare` to your model:

```
