本文整理汇总了PHP中Illuminate\Support\Collection::collapse方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::collapse方法的具体用法?PHP Collection::collapse怎么用?PHP Collection::collapse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::collapse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rowsUngrouped
public function rowsUngrouped()
{
if (!isset($this->rows)) {
$this->rows = $this->rows();
}
return $this->rows instanceof GroupedCollection ? new Collection($this->rows->collapse()) : $this->rows;
}
示例2: call
/**
* @param $resource
* @param array $arguments
* @param string $method
* @return string
* @throws Exception
*/
private function call($resource, $arguments, $method)
{
try {
$request = $this->client->{$method}($this->endpoint . $resource, ['headers' => ['Authorization' => 'apikey ' . $this->apikey, 'Content-type' => 'application/json'], 'body' => json_encode($arguments)]);
$collection = new Collection($request->json());
if ($collection->count() == 1) {
return $collection->collapse();
}
return $collection;
} catch (RequestException $e) {
throw new Exception($e->getResponse()->getBody());
}
}
示例3: makeRequest
/**
* @param string $resource
* @param array $arguments
* @param string $method
* @return string
* @throws Exception
*/
private function makeRequest($resource, $arguments, $method)
{
try {
$options = $this->getOptions($method, $arguments);
$response = $this->client->{$method}($this->endpoint . $resource, $options);
$collection = new Collection(json_decode($response->getBody(), true));
if ($collection->count() == 1) {
return $collection->collapse();
}
return $collection;
} catch (ClientException $e) {
throw new Exception($e->getResponse()->getBody());
} catch (RequestException $e) {
$response = $e->getResponse();
if ($response instanceof ResponseInterface) {
throw new Exception($e->getResponse()->getBody());
}
throw new Exception($e->getMessage());
}
}
示例4: testCollapseWithNestedCollactions
public function testCollapseWithNestedCollactions()
{
$data = new Collection([new Collection([1, 2, 3]), new Collection([4, 5, 6])]);
$this->assertEquals([1, 2, 3, 4, 5, 6], $data->collapse()->all());
}