diff --git a/src/flextype/app/Support/Collection.php b/src/flextype/app/Support/Collection.php index 1c2154dc..a1d4ca5f 100644 --- a/src/flextype/app/Support/Collection.php +++ b/src/flextype/app/Support/Collection.php @@ -141,6 +141,26 @@ class Collection return $this; } + /** + * Get a subset of the items from the given collection. + * + * @param array $array + * @param array|string $keys + * @return static + */ + public function only($keys) + { + $result = []; + + foreach ($this->collection->toArray() as $key => $value) { + $result[$key] = array_intersect_key($value, array_flip((array) $keys)); + } + + $this->collection = new ArrayCollection($result); + + return $this; + } + /** * Sets the where expression to evaluate when this Criteria is searched for. * diff --git a/src/flextype/app/Support/Helpers/CollectionHelper.php b/src/flextype/app/Support/Helpers/CollectionHelper.php index a8b320e6..ba9a91d1 100644 --- a/src/flextype/app/Support/Helpers/CollectionHelper.php +++ b/src/flextype/app/Support/Helpers/CollectionHelper.php @@ -100,6 +100,11 @@ if (! function_exists('collect_filter')) { $collection->orderBy($bind_order_by['order_by']['field'], $bind_order_by['order_by']['direction']); } + // Exec: only + if (isset($filter['only'])) { + $collection->only($filter['only']); + } + // Gets a native PHP array representation of the collection. switch ($bind_return) { case 'first':