PHP code example of yediyuz / laravel-cloudflare-cache

1. Go to this page and download the library: Download yediyuz/laravel-cloudflare-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yediyuz / laravel-cloudflare-cache example snippets


Route::cache()->group(function () {
    Route::get('/content', function () {
        return 'content';
    });
});

Route::cache(tags: ['tag1', 'tag2'], ttl: 600)->group(function () {
    Route::get('/content_with_tags', function () {
        return 'content';
    });
});

Route::cache(tags: ['staticPages'])->group(function () {
    //
});

CloudflareCache::purgeEverything()

CloudflareCache::purgeByUrls([
    'https://example.com/hello',
])

CloudflareCache::purgeByPrefixes([
    'www.example.com/foo',
])

CloudflareCache::purgeByTags([
    'staticPages',
])

CloudflareCache::purgeByHosts([
    'www.example.com',
    'images.example.com',
])



namespace App\Http\Controllers;

use App\Http\Requests\UpdatePostRequest;
use App\Models\Post;
use Yediyuz\CloudflareCache\Facades\CloudflareCache;

class PostController extends Controller
{
    public function update(Post $post, UpdatePostRequest $request)
    {
        $post->update($request->validated());

        CloudflareCache::purgeByUrls([
            route('post.show', $post->id)
        ]);

        return back()->with('message', 'Post updated and url cache purged');
    }
}
bash
php artisan vendor:publish --tag="cloudflare-cache-config"