### Image and Snapshot Operations with DigitalOcean Facade in PHP Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Provides examples for managing droplet images and snapshots using the DigitalOcean facade. It covers listing all images, getting a specific image, creating a droplet snapshot, listing user snapshots, deleting images, and transferring images between regions. Requires the DigitalOcean facade. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // List all available images $images = DigitalOcean::image()->getAll(); foreach ($images as $image) { echo "{$image->name} - {$image->distribution} {$image->slug}\n"; } // Get specific image $image = DigitalOcean::image()->getById(12345678); // Create snapshot of a droplet DigitalOcean::droplet()->snapshot(12345, [ 'name' => 'web-server-backup-2024-01-02', ]); // List user snapshots $snapshots = DigitalOcean::snapshot()->getAll(); foreach ($snapshots as $snapshot) { echo "{$snapshot->name} - {$snapshot->size_gigabytes}GB\n"; } // Delete an image DigitalOcean::image()->delete(12345678); // Transfer image to another region DigitalOcean::image()->transfer(12345678, [ 'type' => 'transfer', 'region' => 'sfo3', ]); ``` -------------------------------- ### Basic Usage with Facade Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md Demonstrates basic usage of the Laravel DigitalOcean package using the facade. This example shows how to power on a droplet and retrieve all available sizes. It assumes default connection settings are configured. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; DigitalOcean::droplet()->powerOn(12345); DigitalOcean::size()->getAll(); ``` -------------------------------- ### Install Laravel DigitalOcean using Composer Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md This command installs the latest version of the Laravel DigitalOcean package using Composer. Ensure you have Composer installed and configured for your project. ```bash $ composer require "graham-campbell/digitalocean:^11.0" ``` -------------------------------- ### Manage DigitalOcean Droplets using Facade Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Demonstrates how to interact with DigitalOcean droplets (power on, get, create, list, delete) using the package's facade. Requires DigitalOcean service to be configured. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Power on a droplet DigitalOcean::droplet()->powerOn(12345); // Get droplet by ID $droplet = DigitalOcean::droplet()->getById(12345); echo $droplet->name; // "web-server-01" echo $droplet->status; // "active" // Create a new droplet $newDroplet = DigitalOcean::droplet()->create([ 'name' => 'api-server-01', 'region' => 'nyc3', 'size' => 's-1vcpu-1gb', 'image' => 'ubuntu-22-04-x64', 'ssh_keys' => [12345678], 'backups' => false, 'ipv6' => true, 'monitoring' => true, ]); // List all droplets $droplets = DigitalOcean::droplet()->getAll(); foreach ($droplets as $droplet) { echo "{$droplet->name}: {$droplet->networks->v4[0]->ip_address}\n"; } // Delete a droplet DigitalOcean::droplet()->delete(12345); ``` -------------------------------- ### Usage with Specific Connection Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md Shows how to use a specific DigitalOcean connection by name. This allows managing multiple configurations within the application. The example retrieves a droplet by ID using a named connection. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; DigitalOcean::connection('your_connection_name')->droplet()->getById(12345); ``` -------------------------------- ### Manage SSH Keys with DigitalOcean SDK Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt This snippet demonstrates how to manage SSH keys for secure droplet access using the DigitalOcean PHP SDK. It covers adding, listing, retrieving, updating, and deleting SSH keys. Ensure the DigitalOcean SDK is installed and configured. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Add SSH key $key = DigitalOcean::key()->create([ 'name' => 'Work Laptop', 'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC... user@host', ]); // List all SSH keys $keys = DigitalOcean::key()->getAll(); foreach ($keys as $key) { echo "ID: {$key->id} - Name: {$key->name}\n"; echo "Fingerprint: {$key->fingerprint}\n"; } // Get SSH key by ID $key = DigitalOcean::key()->getById(12345678); // Update SSH key name DigitalOcean::key()->update(12345678, [ 'name' => 'Production Server Key', ]); // Delete SSH key DigitalOcean::key()->delete(12345678); ``` -------------------------------- ### Volume and Storage Management with DigitalOcean Facade in PHP Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Illustrates how to manage DigitalOcean block storage volumes using the DigitalOcean facade. Operations include creating, retrieving, attaching, detaching, listing, and deleting volumes. Depends on the DigitalOcean facade being available. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Create a volume $volume = DigitalOcean::volume()->create([ 'size' => 100, // GB 'name' => 'database-storage', 'description' => 'PostgreSQL data volume', 'region' => 'nyc3', 'filesystem_type' => 'ext4', ]); // Get volume by ID $volume = DigitalOcean::volume()->getById('506f78a4-e098-11e5-ad9f-000f53306ae1'); echo "Volume: {$volume->name} - {$volume->size_gigabytes}GB\n"; // Attach volume to droplet DigitalOcean::volume()->attach( '506f78a4-e098-11e5-ad9f-000f53306ae1', ['droplet_id' => 12345, 'region' => 'nyc3'] ); // Detach volume DigitalOcean::volume()->detach( '506f78a4-e098-11e5-ad9f-000f53306ae1', ['droplet_id' => 12345, 'region' => 'nyc3'] ); // List all volumes $volumes = DigitalOcean::volume()->getAll(); foreach ($volumes as $volume) { echo "{$volume->name}: {$volume->size_gigabytes}GB - {$volume->region->name}\n"; } // Delete volume DigitalOcean::volume()->delete('506f78a4-e098-11e5-ad9f-000f53306ae1'); ``` -------------------------------- ### Query Region and Size Information with DigitalOcean SDK Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt This section shows how to retrieve information about available regions and droplet sizes for infrastructure planning using the DigitalOcean PHP SDK. It includes fetching all regions, all sizes, and filtering sizes by region availability. This helps in making informed decisions about droplet deployment. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Get all available regions $regions = DigitalOcean::region()->getAll(); foreach ($regions as $region) { echo "{$region->name} ({$region->slug})\n"; echo " Available: " . ($region->available ? 'Yes' : 'No') . "\n"; echo " Features: " . implode(', ', $region->features) . "\n"; } // Get all droplet sizes $sizes = DigitalOcean::size()->getAll(); foreach ($sizes as $size) { echo "{$size->slug}: {$size->vcpus} vCPUs, {$size->memory}MB RAM, "; echo "{$size->disk}GB SSD - ${$size->price_monthly}/month\n"; } // Filter sizes by region availability $nycSizes = array_filter( DigitalOcean::size()->getAll(), fn($size) => in_array('nyc3', $size->regions) ); ``` -------------------------------- ### Load Balancer Configuration with DigitalOcean Facade in PHP Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Shows how to configure and manage DigitalOcean load balancers using the DigitalOcean facade. This includes creating load balancers with forwarding rules and health checks, retrieving them, adding/removing droplets, and deleting them. Requires the DigitalOcean facade. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Create a load balancer $loadBalancer = DigitalOcean::loadBalancer()->create([ 'name' => 'web-lb-01', 'algorithm' => 'round_robin', 'region' => 'nyc3', 'forwarding_rules' => [ [ 'entry_protocol' => 'https', 'entry_port' => 443, 'target_protocol' => 'http', 'target_port' => 80, 'certificate_id' => 'cert-uuid', 'tls_passthrough' => false, ], ], 'health_check' => [ 'protocol' => 'http', 'port' => 80, 'path' => '/health', 'check_interval_seconds' => 10, 'response_timeout_seconds' => 5, 'healthy_threshold' => 3, 'unhealthy_threshold' => 3, ], 'droplet_ids' => [12345, 12346, 12347], ]); // Get load balancer $lb = DigitalOcean::loadBalancer()->getById('lb-uuid'); echo "Load Balancer IP: {$lb->ip}\n"; // Add droplets to load balancer DigitalOcean::loadBalancer()->addDroplets('lb-uuid', [12348, 12349]); // Remove droplets DigitalOcean::loadBalancer()->removeDroplets('lb-uuid', [12348]); // Delete load balancer DigitalOcean::loadBalancer()->delete('lb-uuid'); ``` -------------------------------- ### Retrieve Account Information with DigitalOcean SDK Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt This PHP snippet demonstrates how to fetch account details, including email, UUID, status, and various limits, using the DigitalOcean SDK. This is useful for monitoring account usage and administrative purposes. Ensure the SDK is properly configured to access account information. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Get account information $account = DigitalOcean::account()->getUserInformation(); echo "Email: {$account->email}\n"; echo "UUID: {$account->uuid}\n"; echo "Status: {$account->status}\n"; echo "Droplet Limit: {$account->droplet_limit}\n"; echo "Floating IP Limit: {$account->floating_ip_limit}\n"; echo "Email Verified: " . ($account->email_verified ? 'Yes' : 'No') . "\n"; ``` -------------------------------- ### Switch Between Multiple DigitalOcean Connections Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Illustrates how to manage and switch between different DigitalOcean API connections defined in the configuration. This allows using multiple accounts or tokens within the same Laravel application. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Use the default connection (main) $mainDroplets = DigitalOcean::droplet()->getAll(); // Use a specific connection $secondaryDroplets = DigitalOcean::connection('secondary')->droplet()->getAll(); // Get current default connection $default = DigitalOcean::getDefaultConnection(); // "main" // Change default connection DigitalOcean::setDefaultConnection('secondary'); // Disconnect a specific connection DigitalOcean::disconnect('secondary'); // Reconnect DigitalOcean::reconnect('secondary'); // Get all active connections $connections = DigitalOcean::getConnections(); ``` -------------------------------- ### Usage with Dependency Injection Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md Demonstrates how to use the DigitalOceanManager class with dependency injection in a Laravel application. This approach avoids using facades and allows for easier testing and management of dependencies. ```php use GrahamCampbell\DigitalOcean\DigitalOceanManager; class Foo { public function __construct( private readonly DigitalOceanManager $digitalocean, ) { } public function bar() { $this->digitalocean->region()->getAll(); } } app(Foo::class)->bar(); ``` -------------------------------- ### Manage DigitalOcean Domains and DNS Records Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Shows how to manage domains and DNS records (A, CNAME) for your DigitalOcean account using the package's facade. This includes creating, retrieving, and deleting domains and records. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Create a domain $domain = DigitalOcean::domain()->create('example.com', '192.168.1.1'); // Get all domains $domains = DigitalOcean::domain()->getAll(); foreach ($domains as $domain) { echo "{$domain->name} - {$domain->ttl}\n"; } // Create an A record $record = DigitalOcean::domainRecord()->create('example.com', [ 'type' => 'A', 'name' => 'www', 'data' => '192.168.1.100', 'ttl' => 3600, ]); // Create a CNAME record DigitalOcean::domainRecord()->create('example.com', [ 'type' => 'CNAME', 'name' => 'blog', 'data' => '@', 'ttl' => 3600, ]); // List all records for a domain $records = DigitalOcean::domainRecord()->getAll('example.com'); foreach ($records as $record) { echo "{$record->type}: {$record->name} -> {$record->data}\n"; } // Delete a domain DigitalOcean::domain()->delete('example.com'); ``` -------------------------------- ### Default Connection Behavior Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md Illustrates the default connection behavior in Laravel DigitalOcean. It shows that accessing methods without specifying a connection defaults to the 'main' connection, and demonstrates how to change the default connection. ```php use GrahamCampbell\DigitalOcean\Facades\DigitalOcean; // Identical to using the default 'main' connection DigitalOcean::connection('main')->region()->getAll(); DigitalOcean::region()->getAll(); DigitalOcean::connection()->region()->getAll(); // Checking and changing the default connection DigitalOcean::getDefaultConnection(); // Returns 'main' DigitalOcean::setDefaultConnection('alternative'); ``` -------------------------------- ### Publish Vendor Assets Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md Publishes all vendor assets for the Laravel DigitalOcean package, creating a configuration file at `config/digitalocean.php`. This file is used to set up connection configurations. ```bash php artisan vendor:publish ``` -------------------------------- ### Configure DigitalOcean Connections in Laravel Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Defines the default DigitalOcean connection and lists multiple named connections, each with a specific API token and authentication method. Ensure your API tokens are stored securely in your .env file. ```php return [ 'default' => 'main', 'connections' => [ 'main' => [ 'token' => env('DIGITALOCEAN_TOKEN'), 'method' => 'token', ], 'secondary' => [ 'token' => env('DIGITALOCEAN_SECONDARY_TOKEN'), 'method' => 'token', ], ], ]; ``` -------------------------------- ### Register DigitalOcean Service Provider and Facade in Laravel Source: https://github.com/grahamcampbell/laravel-digitalocean/blob/11.0/README.md This snippet shows how to manually register the DigitalOcean service provider and alias the facade in your Laravel application's config/app.php file. This is necessary if you are not using automatic package discovery. ```php 'DigitalOcean' => GrahamCampbell\DigitalOcean\Facades\DigitalOcean::class, ``` -------------------------------- ### Set DigitalOcean API Tokens in .env File Source: https://context7.com/grahamcampbell/laravel-digitalocean/llms.txt Stores your DigitalOcean API tokens securely in the .env file. These tokens are referenced in the configuration file for authentication. ```env DIGITALOCEAN_TOKEN=dop_v1_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6 DIGITALOCEAN_SECONDARY_TOKEN=dop_v1_z9y8x7w6v5u4t3s2r1q0p9o8n7m6l5k4 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.