PHP code example of spinen / n-central-php-rest-client

1. Go to this page and download the library: Download spinen/n-central-php-rest-client 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/ */

    

spinen / n-central-php-rest-client example snippets


    

    namespace App;

    use Illuminate\Contracts\Auth\MustVerifyEmail;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Notifications\Notifiable;
    use Spinen\Ncentral\Concerns\HasNcentral;

    class User extends Authenticatable
    {
        use HasNcentral, Notifiable;

        // ...
    }
    

> $builder->customers->first()
= Spinen\Ncentral\Customer {#4967
    // properties
  }

> $builder->customers->first()->toArray()
= [
    "customerId" => 249,
    "customerName" => "Customer1",
    "isSystem" => true,
    "isServiceOrg" => true,
    "parentId" => 248,
    "city" => null,
    "stateProv" => null,
    "county" => null,
    "postalCode" => "",
    "contactEmail" => null,
  ]

> $customers = $builder->customers()->take(7)->get()
= Spinen\Ncentral\Support\Collection {#4999
    all: [
      Spinen\Ncentral\Customer {#4991
        // properties
      },
      // more...
    ],
  }

> $customers->count()
= 7

// Could have been $builder->devices()->paginate(2)->page(2)->get()
> $devices = $builder->devices()->page(3, 2)->get()
= Spinen\Ncentral\Support\Collection {#4761
    all: [
      Spinen\Ncentral\Device {#4763
        // properties
      },
      // more...
    ],
  }

> $devices->count()
= 2

> $builder->customers->count()
= 4

$builder->statuses->pluck('customerName', 'customerId')->sort()
= Spinen\Ncentral\Support\Collection {#4959
    all: [
      18 => "Customer A",
      17 => "Customer B",
    ],
  }
bash
    php artisan vendor:publish --tag=ncentral-config
    
bash
    php artisan vendor:publish --tag=ncentral-migrations