當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::pluck方法代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Collection::pluck方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::pluck方法的具體用法?PHP Collection::pluck怎麽用?PHP Collection::pluck使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Database\Eloquent\Collection的用法示例。


在下文中一共展示了Collection::pluck方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: ofProjects

 public static function ofProjects(\Illuminate\Database\Eloquent\Collection $projects)
 {
     return static::whereIn('project_id', $projects->pluck('id'))->orderBy('created_at', 'desc');
 }
開發者ID:titus-toia,項目名稱:treabar,代碼行數:4,代碼來源:Feedable.php

示例2: createMissingAbilities

 /**
  * Create abilities whose name is not in the given list.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $models
  * @param  array  $abilities
  * @param  array  $attributes
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function createMissingAbilities(Collection $models, array $abilities, $attributes = [])
 {
     $missing = array_diff($abilities, $models->pluck('name')->all());
     $created = [];
     foreach ($missing as $ability) {
         $created[] = Models::ability()->create($attributes + ['name' => $ability]);
     }
     return $created;
 }
開發者ID:JosephSilber,項目名稱:bouncer,代碼行數:17,代碼來源:AssociatesAbilities.php

示例3: createMissingAbilities

 /**
  * Create abilities whose name is not in the given list.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $models
  * @param  array  $abilities
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function createMissingAbilities(Collection $models, array $abilities)
 {
     $missing = array_diff($abilities, $models->pluck('name')->all());
     $created = [];
     foreach ($missing as $ability) {
         $created[] = Ability::create(['name' => $ability]);
     }
     return $created;
 }
開發者ID:jmadden,項目名稱:bouncer,代碼行數:16,代碼來源:GivesAbility.php

示例4: __construct

 /**
  * Create a new job instance.
  *
  * @param Collection $requests
  * @param string $token Access token for Vk.com API
  */
 public function __construct(Collection $requests, $token)
 {
     $this->requests = $requests;
     $this->token = (string) $token;
     VkRequest::whereIn('id', $requests->pluck('id')->all())->delete();
 }
開發者ID:atehnix,項目名稱:laravel-vk-requester,代碼行數:12,代碼來源:SendBatch.php

示例5: formatRoles

 /**
  * Get the user's role names.
  *
  * @return string
  */
 public function formatRoles()
 {
     $this->loadRoles();
     return $this->cachedRoles->pluck('name')->implode(', ');
 }
開發者ID:artissant,項目名稱:stock,代碼行數:10,代碼來源:UserViewModel.php

示例6: 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.
     $res = $this->get($columns);
     $results = new Collection($res->getData());
     $values = $results->pluck($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->pluck($key)->all();
         return array_combine($keys, $values);
     }
     return $values;
 }
開發者ID:pin-cnx,項目名稱:orientdb-laravel-5,代碼行數:25,代碼來源:Builder.php

示例7: appendCampaignToCollection

 /**
  * Append Campaign data to the supplied collection.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $collection
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function appendCampaignToCollection($collection)
 {
     $campaignIds = $collection->pluck('campaign_id')->all();
     $campaigns = $this->campaignRepository->getAll($campaignIds);
     $campaigns = $campaigns->keyBy('id')->all();
     foreach ($collection as $contest) {
         if (isset($campaigns[$contest->campaign_id])) {
             $contest->setAttribute('campaign', $campaigns[$contest->campaign_id]);
         } else {
             $contest->setAttribute('campaign', null);
         }
     }
     return $collection;
 }
開發者ID:DoSomething,項目名稱:gladiator,代碼行數:20,代碼來源:Manager.php

示例8: createMissingPermissions

 /**
  * Create permissions whose name is not in the given list.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $models
  * @param  array  $permissions
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function createMissingPermissions(Collection $models, array $permissions)
 {
     $missing = array_diff($permissions, $models->pluck('name')->all());
     $created = [];
     foreach ($missing as $permission) {
         $created[] = Models::permission()->create(['name' => $permission]);
     }
     return $created;
 }
開發者ID:devonzara,項目名稱:bouncer,代碼行數:16,代碼來源:GivesPermission.php


注:本文中的Illuminate\Database\Eloquent\Collection::pluck方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。