Skip to content

Getting started

mozrin edited this page Nov 21, 2026 · 2 revisions

Getting started

This page documents the released 0.9.0 Cirrus package.

Requirements

  • Laravel 12 or 13.
  • PHP 8.4.27+ within the 8.4 line, or PHP 8.5.12+ within the 8.5 line.
  • The PHP filter and JSON extensions.
  • A controlled ingress that establishes the provenance of Cloudflare headers.

Cloudflare must supply the desired headers. Enable IP Geolocation for country information and the Add visitor location headers Managed Transform for the additional location fields. The package reads those values; it does not enable the settings.

Install

composer require moztopia/cloudflare:^0.9
php artisan vendor:publish --tag=cloudflare-config

Composer discovery registers the provider and the Cloudflare facade alias. Applications that disable discovery must register Moztopia\Cloudflare\CloudflareServiceProvider themselves and import the fully qualified facade.

No migrations, queues, scheduled jobs, API credentials or HTTP client setup are required by the core.

Configure ingress explicitly

The published config/cloudflare.php starts with an empty trusted_proxies list. Configure the immediate peer that reaches Laravel:

return [
    'trusted_proxies' => [
        '192.0.2.10',
        '2001:db8::/48',
    ],
];

These are documentation addresses, not real Cloudflare ranges. Replace them with the verified IP addresses or CIDRs for your own topology. Read Trusted ingress before choosing them. Wildcard trust is unsupported.

After changing a deployed application's configuration, clear or rebuild its configuration cache through its normal deployment procedure.

Read the current visitor

use Moztopia\Cloudflare\Facades\Cloudflare;

$visitor = Cloudflare::visitor();
$country = $visitor->countryCode;
$region = $visitor->region;
$timezone = $visitor->timezone;

Every location property is nullable. Unknown values are expected on localhost, when a setting is missing, or when ingress is untrusted. Provide the application's usual fallback rather than guessing a location.

Use dependency injection

use Moztopia\Cloudflare\Cloudflare\Cloudflare as CloudflareContext;

final class DeliveryController
{
    public function __invoke(CloudflareContext $cloudflare)
    {
        return view('delivery', [
            'visitor' => $cloudflare->visitor(),
        ]);
    }
}

The consuming application owns its controller, route and delivery view. The package registers no delivery routes or business policies.

Coexisting with another Cloudflare package

The current release uses the common Cloudflare alias, cloudflare configuration namespace and cloudflare-config publish tag. Other packages may use the same identifiers. Inspect their publishing destinations before publishing, preserve existing configuration and import this package's facade by its full class name in PHP. An explicit PHP import resolves the facade class; it does not eliminate a shared configuration-file collision.

A distinct, backward-compatible coexistence scheme is planned. It has not yet shipped.

See Blade and testing and Visitor and request context for more usage details.

Maintained by-dolly.

Clone this wiki locally