当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::lists方法代码示例

本文整理汇总了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);
 }
开发者ID:iamfaiz,项目名称:lahm,代码行数:8,代码来源:RegressionCalculator.php

示例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());
 }
开发者ID:bigbitecreative,项目名称:paddle,代码行数:16,代码来源:Organisations.php

示例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.*']);
 }
开发者ID:broklyngagah,项目名称:laravel.io,代码行数:9,代码来源:CommentRepository.php

示例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);
         }
     }
 }
开发者ID:aginev,项目名称:acl,代码行数:15,代码来源:SetPermissions.php

示例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;
             }
         }
     }
 }
开发者ID:sebalb,项目名称:shopapp,代码行数:11,代码来源:Product.php

示例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);
 }
开发者ID:rleger,项目名称:TheseEcho,代码行数:31,代码来源:BackupDBTable.php

示例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]);
 }
开发者ID:rbrahul,项目名称:larablog,代码行数:14,代码来源:BlogpostController.php

示例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.*']);
 }
开发者ID:broklyngagah,项目名称:laravel.io,代码行数:18,代码来源:ThreadRepository.php

示例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();
         }
     }
 }
开发者ID:lifeentity,项目名称:membership,代码行数:29,代码来源:Role.php

示例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'));
     });
 }
开发者ID:larrytech,项目名称:calendar,代码行数:13,代码来源:Event.php

示例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();
 }
开发者ID:kleitz,项目名称:bjga-scheduler,代码行数:15,代码来源:ServiceRepository.php

示例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));
 }
开发者ID:eristoddle,项目名称:zen-notebook,代码行数:13,代码来源:Builder.php

示例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'));
 }
开发者ID:roehlerw,项目名称:Kora3,代码行数:22,代码来源:MetadataController.php

示例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();
     }
 }
开发者ID:thinhbuzz,项目名称:laravel-advanced-authorization,代码行数:30,代码来源:UserAuthorizationTrait.php

示例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;
 }
开发者ID:dagmawiyehenew,项目名称:laravel-levapp,代码行数:18,代码来源:AskasService.php


注:本文中的Illuminate\Support\Collection::lists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。