A DigitalOcean API bridge for Laravel

Last update: Jun 22, 2022

Laravel DigitalOcean

Laravel DigitalOcean was created by, and is maintained by Graham Campbell, and is a DigitalOcean PHP API Client bridge for Laravel. It utilises my Laravel Manager package. Feel free to check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.

Banner

Promo Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

Installation

Laravel DigitalOcean requires PHP 7.2-8.0. This particular version supports Laravel 6-8.

DigitalOcean L5.1 L5.2 L5.3 L5.4 L5.5 L5.6 L5.7 L5.8 L6 L7 L8
2.2
3.2
4.0
5.4
6.0
7.3
8.3

To get the latest version, simply require the project using Composer. You will need to install any packages that "provide" psr/http-client-implementation and psr/http-factory-implementation. Most users will want:

For example, to use Guzzle 7:

$ composer require "graham-campbell/digitalocean:^8.3" "guzzlehttp/guzzle:^7.2" "http-interop/http-factory-guzzle:^1.0"

Once installed, if you are not using automatic package discovery, then you need to register the GrahamCampbell\DigitalOcean\DigitalOceanServiceProvider service provider in your config/app.php.

You can also optionally alias our facade:

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

Configuration

Laravel DigitalOcean requires connection configuration.

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish

This will create a config/digitalocean.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.

There are two config options:

Default Connection Name

This option ('default') is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is 'main'.

DigitalOcean Connections

This option ('connections') is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like. Note that the 2 supported authentication methods are: "none" and "token".

Usage

DigitalOceanManager

This is the class of most interest. It is bound to the ioc container as 'digitalocean' and can be accessed using the Facades\DigitalOcean facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of my Laravel Manager package, so you may want to go and checkout the docs for how to use the manager class over at that repo. Note that the connection class returned will always be an instance of DigitalOceanV2\Client.

Facades\DigitalOcean

This facade will dynamically pass static method calls to the 'digitalocean' object in the ioc container which by default is the DigitalOceanManager class.

DigitalOceanServiceProvider

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.

Real Examples

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is main. After you enter your authentication details in the config file, it will just work:

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

The digitalocean manager will behave like it is a DigitalOceanV2\Client class. If you want to call specific connections, you can do with the connection method:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

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

With that in mind, note that:

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

If you prefer to use dependency injection over facades like me, then you can easily inject the manager like so:

use GrahamCampbell\DigitalOcean\DigitalOceanManager;
use Illuminate\Support\Facades\App; // you probably have this aliased already

class Foo
{
    protected $digitalocean;

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

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

App::make('Foo')->bar();

For more information on how to use the DigitalOceanV2\Client class we are calling behind the scenes here, check out the docs at https://github.com/DigitalOceanPHP/Client/tree/4.3.0#examples, and the manager class at https://github.com/GrahamCampbell/Laravel-Manager#usage.

Further Information

There are other classes in this package that are not documented here. This is because they are not intended for public use and are used internally by this package.

Security

If you discover a security vulnerability within this package, please send an email to Graham Campbell at [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here.

License

Laravel DigitalOcean is licensed under The MIT License (MIT).

For Enterprise

Available as part of the Tidelift Subscription

The maintainers of graham-campbell/digitalocean and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

GitHub

https://github.com/GrahamCampbell/Laravel-DigitalOcean
Comments
  • 1. phpstorm does not recognize facade, even with ide-helper

    hi there. i installed the ide-helper and tried stuff like that:

    https://stackoverflow.com/a/51849199/1092858

    but i am not able to make phpstorm recognize commands like this:

    DigitalOcean::droplet()->getAll()

    "droplet" and all other commands are unknown. any idea ?

    thanks!

    Reviewed by michabbb at 2019-04-05 18:41
  • 2. Dynamically set the API access token

    I have the bridge working beautifully with my static token setting as described in your setup documentation (using guzzle5). Everything works as expected but I would like to be able to set the token 'on the fly' if you will.

    Can you explain how I can override the token?

    Reviewed by 06chaynes at 2015-12-04 15:03
  • 3. Help needed. Dynamic API token

    So far I have this put in a InitializeDO method. Not sure if it's the right way but it works just fine. Correct me if there's a better way to set the API token dynamically.

    $this->adapter = new Adapters\ConnectionFactory();
    $config = [
    	'driver'  => 'guzzlehttp',
    	'token'   => Auth::user()->do_api_token
    ];
    $this->adapter->make($config);
    $this->dof = new DigitalOceanFactory($this->adapter);
    $this->dof->make($config);
    $this->do = $this->dof->make($config);
    

    The problem is that I can't access the user(Auth::user()) in the consturctor of the controller, so I'm calling InitializeDO in each one of my methods(index, show, edit, etc.). I don't think this is the best approach. And here comes my question, how can I write this, so it's called just once and working with $this->do afterwards?

    Reviewed by BKirev at 2018-06-27 21:42
  • 4. Installed

    Hey,

    I was hope you could give me some pointers on how to get this working? So far I have go this installed and added a token. How do I say list the droplets on my account or see if its even corrected to my the API successfully?

    Cheers.

    Reviewed by JBird608 at 2018-02-18 18:15
  • 5. Add option for UserData on droplet()->create

    It would be great if you (or someone else more knowledgable than myself) could add in the ability to pass UserData on new droplet creation.

    This would likely need some conditional checking before running the call as UserData is only available on selected OSs in certain locations. More at https://developers.digitalocean.com/#create-a-new-droplet

    Reviewed by railto at 2014-12-08 18:29
  • 6. TTL not set while creating domain record

    Hi Graham I have been trying set TTL on the domain record create and update methods but no luck.

    The toin0u library did not state it either // return the DomainRecord entity 123 of the domain 'baz.dk' updated with new-name, new-data, priority 1, port 2, weight 3, flags 0, tag issue (name, data, priority, port, weight, flags and tag are nullable) $updated = $domainRecord->update('baz.dk', 123, 'new-name', 'new-data', 1, 2, 3, 0, 'issue');

    kindly assist

    Reviewed by aadags at 2019-10-27 17:13
  • 7. Unable to configure

    Hi,

    I installed the package as per the instructions with guzzlehttp. I have put my DO token in config/digitalocean.php but no matter which connection I try to use, I always get Connection {connection_name} is not configured. Please guide me as to where am I going wrong. Thanks!

    Reviewed by radua at 2020-02-20 19:55
  • 8. Laravel 5.7 Call to a member function getBody() on null

        "graham-campbell/digitalocean": "^5.1",
        "guzzlehttp/guzzle": "^6.3",
        "kriswallsmith/buzz": "^0.17.2"
    

    when calling any function for example DigitalOcean::size()->getAll();

    Issue with C:\xampp\htdocs\front\myadmin\vendor\toin0u\digitalocean-v2\src\Adapter\GuzzleHttpAdapter.php

    Line 132: $body = (string) $this->response->getBody();

    Any ideas

    Reviewed by AndreFabris at 2019-02-11 22:09
  • 9. Not compatible Laravel 5.6

    The package is not compatible with laravel 5.6.x

    Problem 1
        - Conclusion: don't install graham-campbell/digitalocean v4.0.1
        - Conclusion: don't install graham-campbell/digitalocean v4.0.0
        - Conclusion: remove laravel/framework v5.6.1
        - Installation request for graham-campbell/digitalocean ^4.0 -> satisfiable by graham-campbell/digitalocean[4.0.x-dev, v4.0.0, v4.0.1].
        - Conclusion: don't install laravel/framework v5.6.1
        - graham-campbell/digitalocean 4.0.x-dev requires illuminate/support 5.1.*|5.2.*|5.3.*|5.4.*|5.5.* -> satisfiable by illuminate/support[5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34].
        - don't install illuminate/support 5.1.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.2.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.3.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.4.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support 5.5.x-dev|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.1|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.13|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.16|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.2|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.20|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.22|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.25|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.28|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.30|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.31|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.41|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.6|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.1.8|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.19|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.21|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.24|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.25|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.26|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.27|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.28|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.31|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.32|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.37|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.43|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.45|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.6|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.2.7|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.16|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.23|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.3.4|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.13|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.17|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.19|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.27|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.36|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.4.9|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.0|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.16|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.17|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.2|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.28|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.33|don't install laravel/framework v5.6.1
        - don't install illuminate/support v5.5.34|don't install laravel/framework v5.6.1
        - Installation request for laravel/framework (locked at v5.6.1, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.1].
    
    

    #17

    Reviewed by danieluyo at 2018-02-08 22:32
  • 10. Getting a single Droplet?

    Isn't there a method for getting just a single droplet for the specific ID? Like:

        public function power($droplet_id) {
    
            dd(DigitalOcean::droplet($droplet_id));
            return redirect()->back();
        }
    
    Reviewed by itzshahay at 2017-06-27 10:39
  • 11. Issues running publish:config

    when I try and run (using Laravel 5)

    php artisan publish:config graham-campbell/digitalocean

    I get an error:

    exception 'BadMethodCallException' with message 'Call to undefined method [package]' in /home/vagrant/code/l5try/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:140 Stack trace:

    I'm just trying to confirm if this is something I did wrong or if it's because L5 is still in flux.

    Thanks

    Reviewed by snappyio at 2015-01-14 02:14
PHP 5.3+ library which helps you to interact with the DigitalOcean API

DigitalOcean The version 2 of the API will be available soon ! Please visit DigitalOceanV2 and contribute :) This PHP 5.3+ library helps you to intera

Jan 9, 2022
A GitHub API bridge for Laravel
A GitHub API bridge for Laravel

Laravel GitHub Laravel GitHub was created by, and is maintained by Graham Campbell, and is a PHP GitHub API bridge for Laravel. It utilises my Laravel

Jun 20, 2022
[DEPRECATED] A Pusher Channels bridge for Laravel

DEPRECATED Laravel now has built-in support for Pusher Channels. This is now the recommended approach to integrate Channels into a Laravel project. Cu

Jun 16, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Mar 21, 2022
API SDK for OpenTrade Commerce API: Taobao, Alibaba, JD, 1688, Aliexpress, Ebay.

OtapiPhpClient Create Client $client = new OtClient($key, $secret, $lang); key (Access Key) secret (Secret for access key) language (2 symbol lang id

Dec 13, 2021
Fanmade project using Twitter API and Marvel API.
Fanmade project using Twitter API and Marvel API.

Project Marvel Memories A fanmade project in PHP using API Twitter V2, Marvel API and Github action scheduler. What about? Posts a random cover with d

Jun 25, 2022
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

May 27, 2022
API client for ThePay - payment gate API
API client for ThePay - payment gate API

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

May 23, 2022
A simple API documentation package for Laravel using OpenAPI and Redoc

Laravel Redoc Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install this package

Jun 10, 2022
Integrate RajaOngkir API with laravel

Baca ini dalam bahasa: Indonesia This is my package laravel-rajaongkir Installation You can install the package via composer: composer require kodepin

Jun 5, 2022
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an

Jul 3, 2022
Twitch Helix API PHP Wrapper for Laravel
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Jun 29, 2022
Spikkl API client for Laravel

Spikkl for Laravel Spikkl-php-laravel-client incorporates the Spikkl API into your Laravel or Lumen project. Requirements Get yourself a free Spikkl a

Nov 29, 2021
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x

Twitter for PHP Twitter API for Laravel 6.x, 7.x, 8.x (and new versions as they are released). Also supports other frameworks via PHP-DI (or feel free

Jun 30, 2022
MobilePay API for Laravel 9.x

MobilePay for PHP MobilePay API for Laravel 9.x Installation You can install the package via composer: composer require robert-hansen/mobilepay-php Yo

Feb 20, 2022
Laravel 8.x package wrapper library for Metatrader 5 Web API

Laravel 8.x package wrapper library for Metatrader 5 Web API

Apr 17, 2022
PHP library for the Stripe API.

Stripe PHP bindings The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a p

Jul 2, 2022
A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

Jun 25, 2022
A PHP library for communicating with the Twilio REST API and generating TwiML.

twilio-php The default branch name for this repository has been changed to main as of 07/27/2020. Documentation The documentation for the Twilio API c

Jun 22, 2022