Skip to content

Commit

Permalink
+ Pluck method on collection
Browse files Browse the repository at this point in the history
  • Loading branch information
dusterio committed May 8, 2018
1 parent 1f15dde commit 8d1f910
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -91,6 +91,8 @@ $states->setLocale('ru')->sortBy('name'); // States will be sorted by Russian tr
$states->find(['code' => 472039]); // Find 1+ divisions that match specified parameters
$states->findOne(['code' => 472039]); // Return the first match only
$states->findOneByCode(472039); // Convenience magic method
$states->toArray(); // Return a flat array of states
$states->pluck('name'); // Return a flat array of state names
```

## Common methods on division objects
Expand Down
11 changes: 11 additions & 0 deletions src/Collections/MemberCollection.php
Expand Up @@ -53,6 +53,17 @@ public function toArray()
return $array;
}

/**
* @param string $key
* @return array
*/
public function pluck($key)
{
return array_map(function($division) use ($key) {
return isset($division[$key]) ? $division[$key] : null;
}, $this->toArray());
}

/**
* @return mixed
*/
Expand Down

0 comments on commit 8d1f910

Please sign in to comment.