本文整理汇总了PHP中Illuminate\Support\Collection::lists方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::lists方法的具体用法?PHP Collection::lists怎么用?PHP Collection::lists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::lists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculate
public function calculate(Collection $results)
{
$allDelta = $results->lists('delta')->toArray();
$allLambda = $results->lists('lambda')->toArray();
$slope = $this->calculateSlope($allDelta, $allLambda);
$yIntercept = $this->calculateYIntercept($allDelta, $allLambda, $slope);
return new RegressionLine($slope, $yIntercept);
}
示例2: sync
/**
* Sync a user with new organisations.
*
* @param \App\Models\User\User $user
* @param \Illuminate\Support\Collection $organisations
*
* @return void
*/
public function sync(User $user, Collection $organisations)
{
$existing = Organisation::query()->whereIn('id', $organisations->lists('id'))->get();
$user->organisations()->detach();
$organisations = $this->map($organisations);
$organisations = $this->create($organisations, $existing);
$user->organisations()->attach($organisations->lists('id')->toArray());
}
示例3: getForumThreadsByTagsPaginated
public function getForumThreadsByTagsPaginated(Collection $tags, $perPage = 20)
{
$query = $this->model->with(['slug', 'mostRecentChild', 'tags'])->where('type', '=', COMMENT::TYPE_FORUM)->join('comment_tag', 'comments.id', '=', 'comment_tag.comment_id');
if ($tags->count() > 0) {
$query->whereIn('comment_tag.tag_id', $tags->lists('id'));
}
$query->groupBy('comments.id')->orderBy('updated_at', 'desc');
return $query->paginate($perPage, ['comments.*']);
}
示例4: assignPermissions
/**
* Assign permissions to roles
*
* @param Collection $permissions
*/
private function assignPermissions(Collection $permissions)
{
$roles = Role::whereIn('id', $this->role_ids)->get();
if ($roles && $permissions) {
$permission_ids = $permissions->lists('id')->all();
foreach ($roles as $role) {
$role->permissions()->attach($permission_ids);
}
}
}
示例5: setFavourites
static function setFavourites(Collection $products, User $user)
{
$favourites = $user->favourites()->whereIn('product_id', $products->lists('id'))->withPivot('created_at')->get(['product_id as pid', 'favourites.created_at as added_fav']);
foreach ($favourites as $key => $fav) {
foreach ($products as $item) {
if ($item->id == $fav->pid) {
$item->favourite = $fav->added_fav;
}
}
}
}
示例6: saveToCSV
/**
* Save the file to CSV.
*
* @param $path
* @param string $delimiters
* @param string $wrapper
* @param string $prefix
*
* @return mixed
*/
public function saveToCSV($path, $delimiters = ';', $wrapper = '"', $prefix = 'backup')
{
$response = new Collection();
$this->delimiters = $delimiters;
$this->wrapper = $wrapper;
$this->createFileDirectoryIfNeeded($path);
foreach ($this->tablesContent as $tableName => $tableContent) {
// If table is empty, continue to the next
if (!count($tableContent)) {
continue;
}
$fileName = $path . date('Y-m-d-H-i-s') . "-{$prefix}-{$tableName}.csv";
$response->push(['status' => $this->writeCSVFile($fileName, $tableContent), 'tableName' => $tableName, 'filename' => $fileName]);
}
// If there was at least one error
if (in_array(false, $response->lists('status')->all())) {
return Response::make(['message' => 'These was an error !', 'status' => 400, 'data' => $response], 400);
}
$this->dispatcher->fire(new DatabaseTableWasSavedToCSV($response->lists('tableName')->all()));
return Response::make(['message' => 'Saved !', 'status' => 200, 'data' => $response], 200);
}
示例7: index
public function index()
{
$posts = Blog::all();
$post_collection = new Collection($posts);
$blog_id_list = $post_collection->lists('id');
$id_arr = array();
foreach ($blog_id_list as $id) {
array_push($id_arr, $id);
}
$rand_id = mt_rand(0, count($id_arr) - 1);
$banner_post = Blog::findOrFail($id_arr[$rand_id]);
//($banner_post->toArray());
return view('blog.homepage', compact('posts'))->with(['banner_post' => $banner_post]);
}
示例8: getByTagsAndStatusPaginated
public function getByTagsAndStatusPaginated(Collection $tags, $status, $perPage = 20)
{
$query = $this->model->with(['author', 'mostRecentReply', 'acceptedSolution']);
if ($tags->count() > 0) {
$query->join('tagged_items', 'forum_threads.id', '=', 'tagged_items.thread_id')->whereIn('tagged_items.tag_id', $tags->lists('id'));
$query->groupBy('forum_threads.id');
}
if ($status) {
if ($status == 'solved') {
$query->where('solution_reply_id', '>', 0);
}
if ($status == 'open') {
$query->whereNull('solution_reply_id');
}
}
$query->orderBy('updated_at', 'desc');
return $query->paginate($perPage, ['forum_threads.*']);
}
示例9: matchRoles
/**
* Foreach role in the given roles:
* 1. If it doesn't exist in the database then create it
*
* Foreach role in the database roles:
* 1. If it doesn't exist in the given roles then delete it
*
* @param Collection $roles
* @return int
*/
public static function matchRoles(Collection $roles)
{
$dbRoles = static::all();
$types = $roles->lists('type');
$dbTypes = $dbRoles->lists('type');
foreach ($roles as $role) {
// If it doesn't exist in the database
if (!in_array($role->type, $dbTypes)) {
// then create it
$role->save();
}
}
foreach ($dbRoles as $dbRole) {
// If database role doesn't exist in the given roles then delete it
if (!in_array($dbRole->type, $types)) {
$dbRole->delete();
}
}
}
示例10: scopeWhereHasTags
/**
* Gets events which are associated with a list of tags.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Support\Collection $tags
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeWhereHasTags($query, Collection $tags)
{
return $query->whereHas('categories', function ($constraint) use($tags) {
$constraint->whereIn('tags.id', $tags->lists('id'));
});
}
示例11: forDropdown
/**
* Convert a collection for use in a dropdown.
*
* @param Collection $collection
* @param string $key
* @param string $value
* @return array
*/
public function forDropdown(Collection $collection, $key, $value)
{
if ($collection->count() > 0) {
return $collection->lists($value, $key);
}
return $collection->toArray();
}
示例12: 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);
$results = new Collection($this->get($columns));
return $results->lists($columns[0], array_get($columns, 1));
}
示例13: index
/**
* Display all fields and their metadata, visibility option, and new metadata form
*
* @params int $pid, int $fid
* @return Response
*/
public function index($pid, $fid)
{
//Fields that already have metadata do not get sent to the view to be listed
$all_fields = Field::where('pid', $pid)->where('fid', $fid)->get();
$available_fields = new \Illuminate\Support\Collection();
foreach ($all_fields as $field) {
if ($field->metadata()->first() !== null) {
continue;
} else {
$available_fields->push($field);
}
}
$fields = $available_fields->lists('name', 'flid');
$form = Form::find($fid);
return view('metadata.index', compact('pid', 'fid', 'form', 'fields'));
}
示例14: loadPermissions
/**
* Load permissions of user if not exist
*
* @return void
*/
protected function loadPermissions()
{
if (is_null($this->slugPermissions)) {
if ($this->isLoadRoles()) {
if (!$this->isLoadPermissions()) {
$this->roles->load('permissions');
}
} else {
$this->load(['roles.permissions']);
}
$slugPermissions = new Collection();
$permissions = new Collection();
$this->roles->each(function ($item, $key) use(&$permissions, &$slugPermissions) {
$slugPermissions = $slugPermissions->merge($item->permissions->lists('slug'));
$item->permissions->each(function ($v, $k) use(&$permissions) {
$tmpSlug = $permissions->lists('slug');
if ($tmpSlug->search($v->slug) === false) {
$permissions->push($v);
}
});
});
$this->permissions = $permissions;
$this->slugPermissions = $slugPermissions->unique();
}
}
示例15: getProperties
private function getProperties($data)
{
$data = new Collection($data);
$articleNumbers = $data->lists('Artnr');
$properties = DB::connection('askas')->table('Artiklar_Egenskaper')->leftJoin('Artiklar_Egenskaper_Falt', 'Artiklar_Egenskaper.ArtFalt_ID', '=', 'Artiklar_Egenskaper_Falt.ArtFalt_ID')->whereIn('Artiklar_Egenskaper.Artnr', $articleNumbers)->where('Sprak_Suffix', 'SV')->whereNotNull('Namn_SV')->select(['Artiklar_Egenskaper.Artnr', 'Artiklar_Egenskaper.Varde', 'Artiklar_Egenskaper_Falt.Namn_SV'])->get();
$properties = new Collection($properties);
//need to make it an array again. The edit in foreach won't work otherwise
$data = $data->toArray();
foreach ($data as &$article) {
$article = (array) $article;
$article['properties'] = $properties->where('Artnr', $article['Artnr'])->all();
$article['recommendedPrice'] = $this->getProperty($properties, "Rek. pris", $article["Artnr"]);
$article['supplierArticleNumber'] = $this->getProperty($properties, "Leverantörs artikelnummer", $article["Artnr"]);
$article['series'] = $this->getProperty($properties, "SERIE", $article["Artnr"]);
$article['color'] = $this->getProperty($properties, 'Färg', $article["Artnr"]);
}
return $data;
}