Skip to content

Commit

Permalink
Merge pull request #17 from parkourben99/master
Browse files Browse the repository at this point in the history
Add facade for default config
  • Loading branch information
DivineOmega authored Oct 17, 2019
2 parents c5fe42a + c335230 commit bcf931e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ $xero = (new Xero())->app(); # To use the 'default' app in the config
$xero = (new Xero())->app('foobar'); # To use a custom app called 'foobar' in the config file
```

Alternately you can use the Xero facade
*Note this is only for the default config*
```php
use LangleyFoxall\XeroLaravel\Facades\Xero;

# Retrieve all contacts via facade
$contacts = Xero::contacts()->get();

# Retrieve an individual contact by its GUID
$contact = Xero::contacts()->find('34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49');
```

You can then immediately access Xero data using Eloquent-like syntax. The
following code snippet shows the available syntax. When multiple results
are returned from the API they will be returned as Laravel Collection.
Expand All @@ -88,7 +100,7 @@ $contact = $xero->contacts()->find('34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49');
$contacts = $xero->contacts()->find([
'34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49',
'364xxxx7f-2xx3-7xx3-gxx7-6726xxxxhe76',
]);
]);
```

### Available relationships
Expand Down
18 changes: 18 additions & 0 deletions src/Facades/Xero.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace LangleyFoxall\XeroLaravel\Facades;

use Illuminate\Support\Facades\Facade;

class Xero extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Xero';
}
}
17 changes: 17 additions & 0 deletions src/Providers/XeroLaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Illuminate\Support\ServiceProvider;
use LangleyFoxall\XeroLaravel\Constants;
use LangleyFoxall\XeroLaravel\Facades\Xero;

class XeroLaravelServiceProvider extends ServiceProvider
{
Expand All @@ -16,6 +17,10 @@ public function register()
$this->mergeConfigFrom(
Constants::CONFIG_PATH, Constants::CONFIG_KEY
);

$this->app->singleton('Xero', function () {
return (new \LangleyFoxall\XeroLaravel\Xero())->app();
});
}

/**
Expand All @@ -29,4 +34,16 @@ public function boot()
Constants::CONFIG_PATH => config_path(Constants::CONFIG_KEY.'.php'),
]);
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
Xero::class,
];
}
}

0 comments on commit bcf931e

Please sign in to comment.