Skip to content

Commit

Permalink
Merge pull request #8 from langleyfoxall/feature/find-method
Browse files Browse the repository at this point in the history
Improvement and fixes to `find` method
  • Loading branch information
DivineOmega authored Oct 19, 2018
2 parents 995fc8d + 4b60573 commit f4b1206
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Wrappers/QueryWrapper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace LangleyFoxall\XeroLaravel\Wrappers;

use Illuminate\Support\Collection;
use LangleyFoxall\XeroLaravel\Apps\PrivateXeroApp;
use XeroPHP\Remote\Query;

Expand Down Expand Up @@ -79,18 +80,22 @@ public function first()
}

/**
* Retrieves a model if passed a single GUID.
* Retrieves a collection of models if passed an array of GUIDs.
* Retrieves a Xero model if passed a single GUID.
* Retrieves a collection of Xero models if passed an array or collection of GUIDs.
*
* @param string|array $guid
* @param string|array|Collection $guid
* @return null|\XeroPHP\Remote\Collection|\XeroPHP\Remote\Model
* @throws \XeroPHP\Exception
* @throws \XeroPHP\Remote\Exception\NotFoundException
*/
public function find($guid)
{
if (is_object($guid) && get_class($guid)===Collection::class) {
$guid = $guid->toArray();
}

if (is_array($guid)) {
return collect($this->app->loadByGUIDs($this->getClass(), $guid));
return collect($this->app->loadByGUIDs($this->getClass(), implode(',', $guid)));
}

return $this->app->loadByGUID($this->getClass(), $guid);
Expand Down

0 comments on commit f4b1206

Please sign in to comment.