本文整理汇总了PHP中Collection::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::make方法的具体用法?PHP Collection::make怎么用?PHP Collection::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::make方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIndexResponseModels
protected function getIndexResponseModels(array $index_response)
{
$model_collection = $this->whereIn('id', $this->getIdsFromIndexResponse($index_response))->get();
$model_collection = $this->sortIndexResponseModels($model_collection, $index_response['results']);
$meta_collection = \Collection::make($index_response['meta']);
$facets_collection = \Collection::make($index_response['facets']);
$response_collection = \Collection::make([]);
$response_collection->put('meta', $meta_collection);
$response_collection->put('results', $model_collection);
$response_collection->put('facets', $facets_collection);
return \Collection::make($response_collection);
}
开发者ID:ryanrobertsname,项目名称:laravel-elasticsearch-repository,代码行数:12,代码来源:EloquentIndexSearchTrait.php
示例2: hydrate
public static function hydrate($class, $results, $type = "collection", $exists = false)
{
if (!class_exists($class)) {
throw new \Exception("class {$class} not exists!");
} elseif ($type == "collection") {
$models = array();
foreach ($results as $result) {
$model = self::pack($class, $result, $exists);
$models[] = $model;
}
return Collection::make($models);
} else {
$model = self::pack($class, $results, $exists);
return $model;
}
}
示例3: sort
/**
* Sort the array using the given callback.
*
* @param array $array
* @param callable $callback
* @return array
*/
public static function sort($array, callable $callback)
{
return Collection::make($array)->sortBy($callback)->all();
}
示例4: get
/**
* 查询集合
*
* @param array $field
*
* @return array
*/
public function get(array $field = [])
{
if (!empty($field)) {
$this->field($field);
}
if ($results = $this->query($this->build()->select(), $this->build()->getSelectParams())) {
if ($model = $this->getModel()) {
$Collection = Collection::make([]);
foreach ($results as $k => $v) {
$instance = clone $model;
$Collection[$k] = $instance->data($v);
}
return $Collection;
} else {
return $results;
}
}
}
示例5: collect
/**
* @param $data
*
* @return mixed
*/
function collect($data)
{
return \Collection::make($data);
}