craig-ramsay/laravel-xero

A Laravel wrapper for Xero.

v2.0.0 2020-05-29 09:00 UTC

This package is auto-updated.

Last update: 2024-04-29 03:38:50 UTC


README

Laravel wrapper for the Xero PHP SDK developed by Michael Calcinai.

Installation

Install the package via composer.

composer require craig-ramsay/laravel-xero

Laravel 5.5 uses Package Discovery, therefore the Service Provider and Facades are registered automatically.

Publish the configuration file by running the php artisan vendor:publish command. Add your Xero consumer_key, consumer_secret and rsa_private_key to the newly created config/xero.php file. The xero.php config file contains instructions on how to generate these values.

Usage

Use the classes by resolving from the Container or via the Facades. The examples below show different methods of accessing a Xero Private Application and returning the contacts list. The package also allows you to access Xero Partner or Public applications.

Automatic Injection

use XeroPHP\Application\PrivateApplication;

class ContactController {
    protected $xero;

    public function __construct(PrivateApplication $xero)
    {
        $this->xero = $xero;
    }
    
    public function index()
    {
        $contacts = $this->xero->load(\XeroPHP\Models\Accounting\Contact::class)->execute();
    }
}

Resolve out of the Container

use XeroPHP\Application\PrivateApplication;

$xero = app(PrivateApplication::class);

$contacts = $xero->load(\XeroPHP\Models\Accounting\Contact::class)->execute();

or

$xero = app('xeroprivate');

$contacts = $xero->load(\XeroPHP\Models\Accounting\Contact::class)->execute();

Facade

use XeroPrivate;

$contacts = XeroPrivate::load(\XeroPHP\Models\Accounting\Contact::class)->execute();

License

The MIT License (MIT). Please see License File for more information.