当前位置: 首页>>代码示例>>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;未经允许,请勿转载。