Skip to content

Commit bcb499b

Browse files
committed
Add helper method Users::findOne()
1 parent c120509 commit bcb499b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2727
- Added item checkout and scan-in.
2828
- Analytics: The `getRows()` method is deprecated. Iterate over the `Report` instead.
2929
- Made package auto-discoverable in Laravel 5.5+.
30+
- Added helper method `Users::findOne()` to get the first match from a search.
3031

3132
### Changed
3233

src/Model/Model.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* The Model class is our base class.
99
*/
10-
abstract class Model
10+
abstract class Model implements \JsonSerializable
1111
{
1212
/* @var Client */
1313
protected $client;
@@ -75,4 +75,9 @@ public function __get($key)
7575

7676
return null;
7777
}
78+
79+
public function jsonSerialize()
80+
{
81+
return $this->data;
82+
}
7883
}

src/Users/Users.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public function get($user_id, $params = [])
3434
->setParams($params);
3535
}
3636

37+
/**
38+
* Get the first user matching a given query, or NULL if not found.
39+
*
40+
* @param string $query
41+
* @param array $options
42+
* @return User|null
43+
*/
44+
public function findOne($query, array $options = [])
45+
{
46+
return $this->search($query, $options)->current();
47+
}
48+
3749
/**
3850
* Iterates over all users matching the given query.
3951
* Handles continuation.

0 commit comments

Comments
 (0)