ziffmedia/laravel-cloudflare is a Laravel package for a laravel nova tool..
It currently has 4 GitHub stars and 130.896 downloads on Packagist (latest version v1.0.0-beta.2).
Install it with composer require ziffmedia/laravel-cloudflare.
Discover more Laravel packages by ziffmedia
or browse all Laravel packages to compare alternatives.
Last updated


composer require ziffmedia/laravel-cloudflare
php artisan vendor:publish --provider="ZiffMedia\LaravelCloudflare\CloudflareServiceProvider" --tag="config"
To provide the cache purge Tool in your Nova instance, you must register the Tool with your NovaServiceProvider:
// app/Providers/NovaServiceProvider.php
use ZiffMedia\LaravelCloudflare\Nova\Tools\LaravelCloudflareTool;
public function tools()
{
return [
// ...,
LaravelCloudflareTool::make()
];
}
For adding permissions to the Tool, please see the Nova documentation.
Note: The Tool is intended only for urls; setup for Cache Tags is not required if only using the Tool or url purging.
To provide the Cache Purge button on any resource, you must reference the Field and make sure that you have setup the appropriate purge method (url or Cache Tag).
// app/Nova/
use ZiffMedia\LaravelCloudflare\Nova\Fields\ClearCacheButton;
public function fields(Request $request)
{
ClearCacheButton::make('Cloudflare Cache')
->purgeUrls(
['https://www.example.com', 'https://www.example.com/page']
)
->purgeTags(function () {
return $this->cloudflareTagsToClear(); // In order to use this method, you must setup Cache Tags (see below)
})
->hideWhenCreating()
}
Cloudflare has the ability to use a special Cache-Tag header on requests to purge multiple pages instantly. If you intend to only use url purging, you can skip this step. In order to setup the Cache-Tag header, follow the below steps:
debug_cache_tags=1 in the querystring of requests to see the output of the header.// app/Http/Kernel.php
use ZiffMedia\LaravelCloudflare\Middleware\CloudflareTagHeaders;
protected $middlewareGroups = [
'web' => [
// ...
CloudflareTagHeaders::class,
]
];
// app/Http/Controllers/ArticleController.php
use ZiffMedia\LaravelCloudflare\Controllers\Concerns\CloudflareTaggable;
class ArticleController extends Controller
{
use CloudflareTaggable;
public function index()
{
// For a collection of models
$articles = Article::get();
$this->addCloudflareTagsFromCollection($articles); // This will add a tag to the page for each model in the collection
// For a single model
$article = Article::first();
$this->addCloudflareTagFromModel($article); // This will add a tag to the page for a single model
return view(...);
}
}
cloudflareTagsToClear and cloudflareTag methods can be overwritten to allow for customization of tags or purging of additional resources. Here is a basic example implementation for an Article model:// app/Models/Article.php
use ZiffMedia\LaravelCloudflare\Models\Concerns\CloudflareTaggable;
class Article extends Model
{
use CloudflareTaggable;
// ...
}
purge_enabled: Allows for purging to be turned on or offemail: Email address used for authenticating with Cloudflare APIkey: Key used to authenticate with Cloudflare APIzone: Zone used for Cloudflare APIdomains: An array of domains which are allowed to be purged. All url purge requests will be validated against these domains, if any.