PHP code example of graham-campbell / digitalocean

1. Go to this page and download the library: Download graham-campbell/digitalocean library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

graham-campbell / digitalocean example snippets


        'DigitalOcean' => GrahamCampbell\DigitalOcean\Facades\DigitalOcean::class,

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;
// you can alias this in config/app.php if you like

DigitalOcean::droplet()->powerOn(12345);
// we're done here - how easy was that, it just works!

DigitalOcean::size()->getAll();
// this example is simple, and there are far more methods available

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

// select the your_connection_name connection, then get going
DigitalOcean::connection('your_connection_name')->droplet()->getById(12345);

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

// writing this:
DigitalOcean::connection('main')->region()->getAll();

// is identical to writing this:
DigitalOcean::region()->getAll();

// and is also identical to writing this:
DigitalOcean::connection()->region()->getAll();

// this is because the main connection is configured to be the default
DigitalOcean::getDefaultConnection(); // this will return main

// we can change the default connection
DigitalOcean::setDefaultConnection('alternative'); // the default is now alternative

use GrahamCampbell\DigitalOcean\DigitalOceanManager;

class Foo
{
    private DigitalOceanManager $digitalocean;

    public function __construct(DigitalOceanManager $digitalocean)
    {
        $this->digitalocean = $digitalocean;
    }

    public function bar()
    {
        $this->digitalocean->region()->getAll();
    }
}

app(Foo::class)->bar();
bash
$ php artisan vendor:publish