Add Cloudflare ip addresses to trusted proxies for Laravel.

Fund package maintenance!

Installs: 322 888

Dependents: 1

Suggesters: 0

Security: 0

Stars: 123

Watchers: 4

Forks: 17

Open Issues: 2

2.0.0 2021-07-14 15:29 UTC


Add Cloudflare ip addresses to trusted proxies for Laravel.

Latest Version Downloads GitHub Workflow Status Sonar Quality Gate Coverage Status


Install using composer:

composer require monicahq/laravel-cloudflare

You don't need to add this package to your service providers.

Add the middleware in app/Http/Kernel.php, adding a new line in the middleware array:


Existing Laravel application

This middleware uses fideloper/proxy as a backend, so you can remove the other TrustProxies line from the middleware array.

Another option is to extend the App\Http\Middleware\TrustProxies class to Monicahq\Cloudflare\Http\Middleware\TrustProxies:

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Monicahq\Cloudflare\Http\Middleware\TrustProxies as Middleware;

class TrustProxies extends Middleware

If the cloudflare ips are detected, they will be used, and if not the trustproxies one will be.

Refreshing the Cache

This package basically retrieves Cloudflare's IP blocks, and stores them in cache. When request comes, the middleware will get Cloudflare's IP blocks from cache, and load them to trusted proxies.

Thus, you'll need to refresh the cloudflare cache every day

You can use the following command for this:

php artisan cloudflare:reload

Suggestion: add the command in the schedule

Add a new line in app/Console/Kernel.php, in the schedule function:


View current Cloudflare's IP blocks

You can use the following command to see the cached IP blocks.

php artisan cloudflare:view

Option: publish the package config file

If you want, you can publish the package config file to config/laravelcloudflare.php:

php artisan vendor:publish --provider="Monicahq\Cloudflare\TrustedProxyServiceProvider"

This file contains some configurations, but you may not need to change them normally.


Laravel monicahq/laravel-cloudflare
5.x-6.x <= 1.8.0
7.x-8.x >= 2.0.0


This package was inspired by lukasz-adamski/laravel-cloudflare and forked from ogunkarakus/laravel-cloudflare.


Author: Alexis Saettler

This project is part of MonicaHQ.

Copyright (c) 2019-2021.

Licensed under the MIT License. View license.