Handles dispatching of methods against all items in the collection.

Parameters

  • string $method The name of the method to call on each instance in the collection.
  • array $params The parameters to pass on each method call.
  • array $options Specifies options for how to run the given method against the object collection. The available options are: - `'collect'`: If `true`, the results of this method call will be returned wrapped in a new `Collection` object or subclass. - `'merge'`: Used primarily if the method being invoked returns an array. If set to `true`, merges all results arrays into one.

Returns

mixed Returns either an array of the return values of the methods, or the return values wrapped in a `Collection` instance.

Source

						public function invoke($method, array $params = array(), array $options = array()) {
		$class = get_class($this);
		$defaults = array('merge' => false, 'collect' => false);
		$options += $defaults;
		$data = array();

		foreach ($this as $object) {
			$value = call_user_func_array(array(&$object, $method), $params);
			($options['merge']) ? $data = array_merge($data, $value) : $data[$this->key()] = $value;
		}
		return ($options['collect']) ? new $class(compact('data')) : $data;
	}