Laravel
Once installed, if you are not using automatic package discovery, then you need to register the Cloudflare\CloudflareServiceProvider
service provider in your config/app.php
.
You can also optionally alias our facade:
'Cloudflare' => Cloudflare\Facades\Cloudflare::class,
Configuration
Laravel Cloudflare requires connection configuration.
To get started, you'll need to publish all vendor assets:
php artisan vendor:publish
This will create a config/cloudflare.php
file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.
Usage
CloudflareManager
Cloudflare\Client
is bound to the ioc container as 'cloudflare'
and can be accessed using the Facades\Cloudflare
facade.
Facades\Cloudflare
This facade will dynamically pass static method calls to the 'cloudflare'
object in the ioc container which by default is the Cloudflare\Client
class.
CloudflareServiceProvider
This class contains no public methods of interest. This class should be added to the providers array in config/app.php
. This class will setup ioc bindings.
Here you can see an example of just how simple this package is to use. Out of the box. After you enter your token
in the config file, it will just work:
use Cloudflare\Facades\Cloudflare;
// you can alias this in config/app.php if you like
Cloudflare::accounts()->list();
// or
Cloudflare::accounts()->details('ACCOUNT_ID');
If you prefer to use dependency injection over facades, then you can easily inject the manager like so:
use Cloudflare\Client;
class Foo
{
public function __construct(
private Client $cloudflare
) {
}
public function bar()
{
$this->cloudflare->accounts()->details('ACCOUNT_ID');
}
}
app(Foo::class)->bar();