Installation & Getting Started - joshuapack/laravel-cloudflare GitHub Wiki
Install the package by requiring it in composer.
composer require joshuapack/laravel-cloudflare
You no longer need Email and API Key combo and can now setup a token.
Depending on your needs, you can create an Edit zone DNS API token. See https://developers.cloudflare.com/fundamentals/api/get-started/create-token/
In your .env
file add CLOUDFLARE_API_TOKEN
with your API token.
Below is how to use your email and API Key:
Make sure you have the following information:
- Your Cloudflare email, simple, the one you use to log in with.
- Your Cloudflare API Key, found in your account settings.
- (Optional) The Zone ID for the domain you want to edit, this is on the main page for the domain.
Put them in your .env
as the following, obviously and respectively.
CLOUDFLARE_EMAIL
CLOUDFLARE_API_KEY
- (Optional)
CLOUDFLARE_ZONE_ID
When using Laravel 10-12, the service should automatically be included and ready to use.
In my examples, I will be referring to the code app()->make('laravel-cloudflare')
in accessing the service. You can set it to a variable or property so you can access it within that class easier.
For example:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class cloudflare extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cloudflare:cloudflare';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Cloudflare command';
protected $cloudflare = null;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
$this->cloudflare = app()->make('laravel-cloudflare');
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
return 0;
}
}
This would allow you, within your command application to call $this->cloudflare
to the main Cloudflare object. Within the documentation, I will be using $this->cloudflare
to make all the calls to cloudflare. Hopefully that makes sense to you.