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


PHP Collection::find方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::find方法的具体用法?PHP Collection::find怎么用?PHP Collection::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Collection的用法示例。


在下文中一共展示了Collection::find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateArrangement

 public static function updateArrangement(Collection $collection, array $arrangement)
 {
     $order = 0;
     foreach ($arrangement as $parent) {
         /** @var \CipeMotion\Medialibrary\Entities\Category $category */
         $category = $collection->find(array_get($parent, 'id', 0));
         $children = array_get($parent, 'children', []);
         if (!is_null($category)) {
             $category->order = $order;
             $category->parent_id = null;
             $category->save();
             if (count($children) > 0) {
                 $childOrder = 0;
                 foreach ($children as $child) {
                     /** @var \CipeMotion\Medialibrary\Entities\Category $childCategory */
                     $childCategory = $collection->find(array_get($child, 'id', 0));
                     if (!is_null($childCategory)) {
                         $childCategory->order = $childOrder;
                         $childCategory->parent_id = $category->id;
                         $childCategory->save();
                         $childOrder++;
                     }
                 }
             }
             $order++;
         }
     }
 }
开发者ID:cipemotion,项目名称:medialibrary,代码行数:28,代码来源:Category.php

示例2: getCounty

 protected function getCounty($municipality_id)
 {
     $county_id = substr(str_pad($municipality_id, 4, '0', STR_PAD_LEFT), 0, 2);
     /* @var County $county */
     $county = $this->counties->find($county_id);
     return $county;
 }
开发者ID:phaza,项目名称:laravel-norwegian-zip-codes,代码行数:7,代码来源:UpdateZipCodesCommand.php

示例3: __get

 /**
  * Retrieve token data
  *
  * @param string $tokenName
  *
  * @return mixed
  */
 public function __get($tokenName)
 {
     $token = $this->tokens->find($tokenName);
     if (!$token instanceof Token) {
         return null;
     }
     $tokenVal = $token->token_value;
     return $tokenVal;
 }
开发者ID:rendler-denis,项目名称:templatetokens,代码行数:16,代码来源:TokensManager.php

示例4: sortByLikes

 private function sortByLikes(Collection $collection, Collection $orderArray)
 {
     $sorted = new Collection();
     $orderArray->each(function ($orderElem) use($collection, $sorted) {
         if ($collection->contains($orderElem->likeable_id)) {
             $sorted->push($collection->find($orderElem->likeable_id));
         }
     });
     return $sorted;
 }
开发者ID:SenhorBardell,项目名称:yol,代码行数:10,代码来源:FavoritesController.php

示例5: save

 /**
  *
  */
 public function save()
 {
     if (empty($this->data)) {
         return;
     }
     if ($this->relation instanceof Relations\HasMany && is_array($this->data)) {
         if (is_numeric($this->data[0])) {
             $data = new Collection();
             foreach ($this->data as $key => $item) {
                 // $this->data[$key] = $this->related->baseModel->find($item);
                 $data->push($this->related->baseModel->find($item));
             }
         } else {
             $data = new Collection($this->data);
         }
         // detach any existing models and only save the selected ones
         $foreignKey = $this->relation->getPlainForeignKey();
         $current = $this->relation->getResults();
         if (!$current) {
             $this->relation->saveMany($data->toArray());
             return;
         }
         $all = $data->merge($current);
         foreach ($all as $item) {
             if ($keep = $data->find($item->getKey())) {
                 $this->relation->save($keep);
             } else {
                 $item->{$foreignKey} = null;
                 $item->save();
             }
         }
     } else {
         if ($this->relation instanceof Relations\BelongsToMany && is_array($this->data)) {
             if (is_numeric($this->data[0])) {
                 $this->relation->sync($this->data);
             }
         } else {
             /* If we have an id let's grab the model instance, otherwise assume we were given it */
             $this->data = is_numeric($this->data) ? $this->related->baseModel->find($this->data) : $this->data;
             parent::saveRelation($this->relation, $this->data);
         }
     }
 }
开发者ID:packettide,项目名称:bree,代码行数:46,代码来源:Relate.php

示例6: find

 /**
  * {@inheritdoc}
  */
 public function find($id)
 {
     $this->boot();
     return $this->collection->find($id);
 }
开发者ID:khaliqgant,项目名称:Deep,代码行数:8,代码来源:AbstractDeferredRepository.php

示例7: buildItemData

 /**
  * Build the pivot table data for a particular item.
  *
  * @param  mixed                                    $key      The product's primary key.
  * @param  array                                    $data
  * @param  \Illuminate\Database\Eloquent\Collection $products
  *
  * @return array
  */
 protected function buildItemData($key, array $data, Collection $products)
 {
     if (!($product = $products->find($key))) {
         throw new \RuntimeException("ID {$key} not found in products collection");
     }
     $this->setProduct($product);
     if (!empty($data['purchased_amount'])) {
         $data['purchased_for'] = $product->in_price;
     }
     if (!empty($data['sold_amount'])) {
         $data['sold_for'] = $product->out_price;
     }
     return $data;
 }
开发者ID:viniciusferreira,项目名称:laravel-repository,代码行数:23,代码来源:RealWorldExample.php

示例8: updateUserHashtags

 /**
  * Updates the current user's searched hashtags with the specified hashtag
  * $terms and returns the number of hashtags updated or -1 on failure.
  *
  * @param  Collection   $hashtags hashtag collection to update
  * @param  array|string $terms hashtag terms to update with
  * @return integer
  */
 protected function updateUserHashtags(Collection $hashtags, array $terms)
 {
     $num_updates = 0;
     foreach ($terms as $id => $term) {
         // remove whitespace, convert to lowercase
         $term = strtolower(preg_replace('/\\s+/', '', $term));
         if (!empty(trim($term))) {
             // verify hashtag term does not already exists
             $hashtag = $hashtags->first(function ($key, $value) use($id, $term) {
                 return $value->id != $id && $value->term == $term;
             });
             if (isset($hashtag)) {
                 // indicate error has occured
                 $num_updates = -1;
                 \Session::put('error_hashtag_edit_id', $id);
                 \Session::flash('flash_message', 'Hashtag \'' . $term . '\' already exists.');
                 break;
             }
             // update hashtag term if not the same
             $hashtag = $hashtags->find($id);
             if (isset($hashtag) && $hashtag->term != $term) {
                 $hashtag->term = $term;
                 $hashtag->save();
                 $num_updates++;
             }
         }
     }
     return $num_updates;
 }
开发者ID:jasonjyu,项目名称:cscie15-p4,代码行数:37,代码来源:HashtagController.php


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