本文整理汇总了PHP中Illuminate\Support\Collection::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::fetch方法的具体用法?PHP Collection::fetch怎么用?PHP Collection::fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::fetch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lists
/**
* Get an array with the values of a given column.
*
* @param string $column
* @param string $key
* @return array
*/
public function lists($column, $key = null)
{
$columns = $this->getListSelect($column, $key);
// First we will just get all of the column values for the record result set
// then we can associate those values with the column if it was specified
// otherwise we can just give these values back without a specific key.
$results = new Collection($this->get($columns));
$values = $results->fetch($columns[0])->all();
// If a key was specified and we have results, we will go ahead and combine
// the values with the keys of all of the records so that the values can
// be accessed by the key of the rows instead of simply being numeric.
if (!is_null($key) && count($results) > 0) {
$keys = $results->fetch($key)->all();
return array_combine($keys, $values);
}
return $values;
}
示例2: usersTasks
/**
* Resolve company users.
*
* @param \Illuminate\Support\Collection $users
* @param array $args
* @return mixed
*/
public function usersTasks($users, array $args)
{
return $users->fetch(['tasks' => function ($q) use($args) {
$q->loadConnection($args);
}]);
}