本文整理匯總了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());
}