PHP code example of hampel / linode-api-laravel

1. Go to this page and download the library: Download hampel/linode-api-laravel 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/ */

    

hampel / linode-api-laravel example snippets


'providers' => [
    App\Providers\AppServiceProvider::class,
    Hampel\Linode\Api\Laravel\LinodeServiceProvider::class,
],

use Hampel\Linode\Api\Laravel\Facades\Linode;

'default' => 'production',

'accounts' => [
    'production' => [
        'token' => env('LINODE_API_TOKEN'),
    ],

    'staging' => [
        'token' => env('STAGING_LINODE_API_TOKEN'),
    ],
],

'token' => env('LINODE_API_TOKEN') ?: env('LINODE_TOKEN'),

'version' => env('LINODE_API_VERSION', 'v4'),   // v4 or v4beta, and nothing else
'page_size' => env('LINODE_PAGE_SIZE'),         // null uses the API's own default of 100
'base_uri' => env('LINODE_API_URL'),            // null uses Linode's own host

Linode::withVersion('v4beta')->connection()->get('some/beta/endpoint');

'timeout' => 10,
'connect_timeout' => 5,

use Hampel\Linode\Api\Laravel\Facades\Linode;
use Hampel\Linode\Api\Entity\DomainRecord;

Linode::verify();                                          // does this token work?

$zone = Linode::domains()->findByName('example.com');      // null when there is no such zone

Linode::domains()->records($zone)->create(
    DomainRecord::a('www', '203.0.113.10')->withTtl(300)
);

$zones = Linode::client('staging')->domains()->all();

use Hampel\Linode\Api\Laravel\LinodeManager;

public function __construct(private readonly LinodeManager $linode) {}

$this->linode->client('staging')->domains()->all();

use Hampel\Linode\Api\Authentication\AccessToken;

$linode = Linode::withCredential(new AccessToken($tenant->linode_token));

return response()->json(Linode::domains()->get($id));

use Hampel\Linode\Api\Exception\NotFoundException;
use Hampel\Linode\Api\Exception\NotAuthenticatedException;
use Hampel\Linode\Api\Exception\NotPermittedException;

try {
    $zone = Linode::domains()->get($id);
} catch (NotFoundException $e) {
    // no such zone on this account
} catch (NotPermittedException $e) {
    // the token is real and lacks the scope, or the user lacks the grant
} catch (NotAuthenticatedException $e) {
    // the credential is no good. A configuration error, not an empty result.
}

use Illuminate\Support\Facades\Http;

Http::preventStrayRequests();

Http::fake([
    'api.linode.com/*' => Http::response([
        'data' => [['id' => 1234, 'domain' => 'example.com', 'type' => 'master']],
        'page' => 1, 'pages' => 1, 'results' => 1,
    ]),
]);

$zone = Linode::domains()->findByName('example.com');

Http::assertSent(fn ($request) => $request->hasHeader('Authorization'));

$this->app->singleton('linode.http_client', fn ($app) => $app->make(MyPolicyClient::class));
bash
php artisan vendor:publish --tag=linode-config
bash
php <app> vendor:publish --tag=linode-config