PHPackages                             monicahq/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. monicahq/laravel-cloudflare

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

monicahq/laravel-cloudflare
===========================

Add Cloudflare ip addresses to trusted proxies for Laravel.

4.1.0(1mo ago)3372.7M—1%34[5 issues](https://github.com/monicahq/laravel-cloudflare/issues)4MITPHPPHP ^8.2CI passing

Since Oct 5Pushed 1mo ago4 watchersCompare

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

READMEChangelog (10)Dependencies (26)Versions (38)Used By (4)

Trust Cloudflare's Proxies for Laravel
======================================

[](#trust-cloudflares-proxies-for-laravel)

Add Cloudflare ip addresses to trusted proxies for Laravel.

[![Latest Version](https://camo.githubusercontent.com/0a6483a7762e5ea036ac0151c0f8691922da2ae25de775a7ec5f6d7404e6dfe3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f6e69636168712f6c61726176656c2d636c6f7564666c6172653f7374796c653d666c61742d737175617265266c6162656c3d4c617465737425323056657273696f6e)](https://github.com/monicahq/laravel-cloudflare/releases)[![Downloads](https://camo.githubusercontent.com/d52464be9ab7721334b1211eb4fe66aac128b72083b1691c736c5bf4e066a30e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f6e69636168712f6c61726176656c2d636c6f7564666c6172653f7374796c653d666c61742d737175617265266c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/monicahq/laravel-cloudflare)[![Workflow Status](https://camo.githubusercontent.com/346a1ee5667017f6bf71a589b2f54c246d4c259ceecc129ab30c138ba8414bed/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d6f6e69636168712f6c61726176656c2d636c6f7564666c6172652f556e697425323074657374733f7374796c653d666c61742d737175617265266c6162656c3d576f726b666c6f77253230537461747573)](https://github.com/monicahq/laravel-cloudflare/actions?query=branch%3Amain)[![Quality Gate](https://camo.githubusercontent.com/b5edd10a2a22208f357326ae7dc435ca2b01e4c257a91e33037df232be7e6cb2/68747470733a2f2f696d672e736869656c64732e696f2f736f6e61722f7175616c6974795f676174652f6d6f6e69636168715f6c61726176656c2d636c6f7564666c6172653f7365727665723d6874747073253341253246253246736f6e6172636c6f75642e696f267374796c653d666c61742d737175617265266c6162656c3d5175616c69747925323047617465)](https://sonarcloud.io/dashboard?id=monicahq_laravel-cloudflare)[![Coverage Status](https://camo.githubusercontent.com/306d91c846789d9f1e104b0d31f7a0d90358a9960336844d631f3c3442650aa7/68747470733a2f2f696d672e736869656c64732e696f2f736f6e61722f636f7665726167652f6d6f6e69636168715f6c61726176656c2d636c6f7564666c6172653f7365727665723d6874747073253341253246253246736f6e6172636c6f75642e696f267374796c653d666c61742d737175617265266c6162656c3d436f766572616765253230537461747573)](https://sonarcloud.io/dashboard?id=monicahq_laravel-cloudflare)

Installation
============

[](#installation)

1. Install package using composer:

```
composer require monicahq/laravel-cloudflare

```

1. Configure Middleware

Replace `TrustProxies` middleware in your `bootstrap/app.php` file:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->replace(
        \Illuminate\Http\Middleware\TrustProxies::class,
        \Monicahq\Cloudflare\Http\Middleware\TrustProxies::class
    );
})
```

Custom proxies callback
-----------------------

[](#custom-proxies-callback)

You can define your own proxies callback by calling the `LaravelCloudflare::getProxiesUsing()` to change the behavior of the `LaravelCloudflare::getProxies()` method. This method should typically be called in the `boot` method of your `AppServiceProvider` class:

```
use Illuminate\Support\ServiceProvider;
use Monicahq\Cloudflare\LaravelCloudflare;
use Monicahq\Cloudflare\Facades\CloudflareProxies;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        LaravelCloudflare::getProxiesUsing(fn() => CloudflareProxies::load());
    }
}
```

How it works
============

[](#how-it-works)

The middleware uses [Illuminate\\Http\\Middleware\\TrustProxies](https://github.com/laravel/framework/blob/8.x/src/Illuminate/Http/Middleware/TrustProxies.php) as a backend.

When the cloudflare ips are detected, they are used as trusted proxies.

Refreshing the Cache
====================

[](#refreshing-the-cache)

This package 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 as trusted proxies.

You'll need to refresh the cloudflare cache regularely to always have up to date proxy.

Use the `cloudflare:reload` artisan command to refresh the IP blocks:

```
php artisan cloudflare:reload
```

Suggestion: add the reload command in the schedule
--------------------------------------------------

[](#suggestion-add-the-reload-command-in-the-schedule)

Add a schedule to your `routes/console.php` file to refresh the cache, for instance:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('cloudflare:reload')->daily();
```

View current Cloudflare's IP blocks
===================================

[](#view-current-cloudflares-ip-blocks)

You can use the `cloudflare:view` artisan command to see the cached IP blocks:

```
php artisan cloudflare:view
```

Option: publish the package config file
=======================================

[](#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.

Running tests for your package
------------------------------

[](#running-tests-for-your-package)

When running tests for your package, you generally don't need to get Cloudflare's proxy addresses. You can deactivate the Laravel Cloudflare middleware by adding the following environment variable in your `.env` or `phpunit.xml` file:

```
LARAVEL_CLOUDFLARE_ENABLED=false

```

Compatibility
=============

[](#compatibility)

Laravel[monicahq/laravel-cloudflare](https://github.com/monicahq/laravel-cloudflare)5.x-6.x&lt;= 1.87.x-8.532.x8.54-12.03.x&gt;= 11.0&gt;= 4.xCitations
=========

[](#citations)

This package was inspired by [lukasz-adamski/laravel-cloudflare](https://github.com/lukasz-adamski/laravel-cloudflare) and forked from [ogunkarakus/laravel-cloudflare](https://github.com/ogunkarakus/laravel-cloudflare).

License
=======

[](#license)

Author: [Alexis Saettler](https://github.com/asbiin)

This project is part of [MonicaHQ](https://github.com/monicahq/).

Copyright © 2019–2025.

Licensed under the MIT License. [View license](LICENSE.md).

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance89

Actively maintained with recent releases

Popularity62

Solid adoption and visibility

Community30

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~97 days

Recently: every ~186 days

Total

29

Last Release

53d ago

Major Versions

0.2 → 1.0.02018-10-05

1.8.0 → 2.0.02021-07-14

2.0.0 → 3.0.02022-01-14

3.8.0 → 4.0.02025-07-26

PHP version history (5 changes)1.2.0PHP &gt;= 7.1.0

1.3.0PHP &gt;= 7.2.0

1.8.0PHP ^7.2 || ^8.0

3.0.0PHP ^7.4 || ^8.0

4.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e66caa78edaffa8e41c951f9bb469ae0c91ecdf1e1dc7bdfee847d127a5d4d4?d=identicon)[asbin](/maintainers/asbin)

---

Top Contributors

[![asbiin](https://avatars.githubusercontent.com/u/25419741?v=4)](https://github.com/asbiin "asbiin (67 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (49 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (25 commits)")[![MonicaBot](https://avatars.githubusercontent.com/u/40141970?v=4)](https://github.com/MonicaBot "MonicaBot (11 commits)")[![mvdnbrk](https://avatars.githubusercontent.com/u/802681?v=4)](https://github.com/mvdnbrk "mvdnbrk (7 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![Zae](https://avatars.githubusercontent.com/u/96126?v=4)](https://github.com/Zae "Zae (1 commits)")[![alissn](https://avatars.githubusercontent.com/u/26966142?v=4)](https://github.com/alissn "alissn (1 commits)")[![zhanang19](https://avatars.githubusercontent.com/u/19884603?v=4)](https://github.com/zhanang19 "zhanang19 (1 commits)")[![dmyers](https://avatars.githubusercontent.com/u/207171?v=4)](https://github.com/dmyers "dmyers (1 commits)")[![jonnott](https://avatars.githubusercontent.com/u/472468?v=4)](https://github.com/jonnott "jonnott (1 commits)")[![justijndepover](https://avatars.githubusercontent.com/u/9008623?v=4)](https://github.com/justijndepover "justijndepover (1 commits)")[![lloydowen](https://avatars.githubusercontent.com/u/38921542?v=4)](https://github.com/lloydowen "lloydowen (1 commits)")[![rickybarnett](https://avatars.githubusercontent.com/u/10849485?v=4)](https://github.com/rickybarnett "rickybarnett (1 commits)")

---

Tags

cloudflare-ipshacktoberfesttrusted-proxiesphplaravelcloudflareproxies

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/monicahq-laravel-cloudflare/health.svg)

```
[![Health](https://phpackages.com/badges/monicahq-laravel-cloudflare/health.svg)](https://phpackages.com/packages/monicahq-laravel-cloudflare)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[mediconesystems/livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS

1.2k711.3k8](/packages/mediconesystems-livewire-datatables)[kra8/laravel-snowflake

Snowflake for Laravel and Lumen.

188402.3k6](/packages/kra8-laravel-snowflake)[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[napp/xray-laravel

AWS X-Ray for Laravel applications.

61407.3k](/packages/napp-xray-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
