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


PHP Collection::keyBy方法代碼示例

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


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

示例1: getCollectionFromCart

 public function getCollectionFromCart($cart)
 {
     $collection = new Collection();
     if ($cart->ProductCount == 1) {
         $collection = new Collection([$cart->Items->CartLine]);
     } elseif ($cart->ProductCount > 1) {
         $collection = new Collection($cart->Items->CartLine);
     }
     return $collection->keyBy('ProductId');
 }
開發者ID:Assassinsscript,項目名稱:CrisisCenter,代碼行數:10,代碼來源:CDiscountAPI.php

示例2: index

 public function index($year, $month)
 {
     $photos = new Collection();
     for ($date = $this->createDate($year, $month); $date->month == $month; $date->addDay()) {
         $photo = new Photo($date->copy());
         if ($photo->exists()) {
             $photos->push($photo);
         }
     }
     return response()->json($photos->keyBy('index'));
 }
開發者ID:simondubois,項目名稱:photos,代碼行數:11,代碼來源:PhotoController.php

示例3: select

 /**
  * From collection get the list use for generate select box HTML::select
  * The final result will be:
  * <pre>
  *  [id => name]
  * </pre>
  *
  * @param \Illuminate\Support\Collection $collection
  *
  * @return array
  */
 function select($collection)
 {
     $area = $collection->keyBy('id')->toArray();
     foreach ($area as $k => $v) {
         $area[$k] = $v['name'];
     }
     return $area;
 }
開發者ID:vuongabc92,項目名稱:researchdrupal7cmsasbeginer,代碼行數:19,代碼來源:helpers.php

示例4: testKeyByClosure

 public function testKeyByClosure()
 {
     $data = new Collection([['firstname' => 'Taylor', 'lastname' => 'Otwell', 'locale' => 'US'], ['firstname' => 'Lucas', 'lastname' => 'Michot', 'locale' => 'FR']]);
     $result = $data->keyBy(function ($item, $key) {
         return strtolower($key . '-' . $item['firstname'] . $item['lastname']);
     });
     $this->assertEquals(['0-taylorotwell' => ['firstname' => 'Taylor', 'lastname' => 'Otwell', 'locale' => 'US'], '1-lucasmichot' => ['firstname' => 'Lucas', 'lastname' => 'Michot', 'locale' => 'FR']], $result->all());
 }
開發者ID:sa7bi,項目名稱:euro16,代碼行數:8,代碼來源:SupportCollectionTest.php

示例5: checkMultiGetResults

 /**
  * Checks the results of a multi GET for errors.
  *
  * @param  array $results
  * @param  \Illuminate\Support\Collection $collection
  * @throws \Elodex\Exceptions\MultiGetException
  */
 protected function checkMultiGetResults(array $results, BaseCollection $collection)
 {
     $modelDictionary = $collection->keyBy('id')->all();
     $failedItems = [];
     $errors = [];
     foreach ($results['docs'] as $doc) {
         $documentId = $doc['_id'];
         if (isset($doc['error'])) {
             $failedItems[$documentId] = $modelDictionary[$documentId];
             $errors[$documentId] = $doc['error'];
             continue;
         }
         if ($doc['found'] === false) {
             $failedItems[$documentId] = $modelDictionary[$documentId];
             $errors[$documentId] = ['reason' => 'document not found'];
         }
     }
     if (!empty($failedItems)) {
         throw MultiGetException::createForFailedItems($failedItems, $errors);
     }
 }
開發者ID:elodex,項目名稱:elodex,代碼行數:28,代碼來源:IndexRepository.php

示例6: setProperties

 /**
  * Set relation properties.
  *
  * @param BaseCollection|null $properties
  */
 public function setProperties(BaseCollection $properties = null)
 {
     $this->properties = $properties === null ? null : $properties->keyBy('name');
 }
開發者ID:dkulyk,項目名稱:eloquent-extra,代碼行數:9,代碼來源:Values.php

示例7: getIds

 /**
  * @return array
  */
 public function getIds()
 {
     return $this->fields->keyBy(function (FieldInterface $field) {
         return $field->getId();
     })->keys()->all();
 }
開發者ID:KodiComponents,項目名稱:module-datasource,代碼行數:9,代碼來源:FieldsCollection.php


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