Package Data | |
---|---|
Maintainer Username: | asbin |
Maintainer Contact: | alexis@saettler.org (Alexis Saettler) |
Package Create Date: | 2018-10-05 |
Package Last Update: | 2024-05-04 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:20:16 |
Package Statistics | |
---|---|
Total Downloads: | 1,646,758 |
Monthly Downloads: | 49,258 |
Daily Downloads: | 2,047 |
Total Stars: | 276 |
Total Watchers: | 5 |
Total Forks: | 29 |
Total Open Issues: | 3 |
Add Cloudflare ip addresses to trusted proxies for Laravel.
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:
\Monicahq\Cloudflare\Http\Middleware\TrustProxies::class
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.
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
Add a new line in app/Console/Kernel.php
, in the schedule
function:
$schedule->command('cloudflare:reload')->daily();
You can use the following command to see the cached IP blocks.
php artisan cloudflare:view
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.
This package supports Laravel 5.6 or newer.
This repository licensed under the MIT license.
This package was inspired by lukasz-adamski/laravel-cloudflare and forked from ogunkarakus/laravel-cloudflare.