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


PHP Collection::filter方法代码示例

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


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

示例1: map

 public function map($hash, $title = true)
 {
     if (strlen($hash) < 1) {
         $hash = '9999999999';
     }
     if (Hashes::$items == null) {
         $this->getItems();
     }
     $object = Hashes::$items->filter(function ($item) use($hash) {
         return $item->hash == $hash;
     })->first();
     if ($object instanceof Hash) {
         if ($title) {
             return $object->title;
         }
         return $object;
     } else {
         if ($this->allowedRetry) {
             $this->updateHashes();
             return $this->map($hash, $title);
         } else {
             $classified = Hash::where('hash', '9999999999')->first();
             if ($title) {
                 return $classified->title;
             }
             return $classified;
             // throw new HashNotLocatedException($hash);
         }
     }
 }
开发者ID:GMSteuart,项目名称:PandaLove,代码行数:30,代码来源:Hashes.php

示例2: handle

 /**
  * Execute the job.
  *
  * @return Collection
  */
 public function handle()
 {
     return $this->bookings->filter(function ($booking) {
         $value = 0;
         $payed = 0;
         foreach ($booking->customer_booking as $customer) {
             if ($customer->price) {
                 $value += $customer->price->price;
             }
         }
         foreach ($booking->payment as $payment) {
             $payed += $payment->value;
         }
         if ($value === $payed) {
             return true;
         }
         return false;
     })->sortByDesc('id');
 }
开发者ID:ChristianEGOL,项目名称:reisen-lizenz-tool-payment,代码行数:24,代码来源:BookingPayedJob.php

示例3: isEnabledKey

 /**
  * Return true if all API Key are still enable
  *
  * @param Collection $keys
  * @return bool
  */
 protected function isEnabledKey(Collection $keys)
 {
     // count keys with enable value and compare it to total keys number
     $enabledKeys = $keys->filter(function ($item) {
         return $item->enabled == 1;
     })->count();
     if ($enabledKeys == $keys->count() && $keys->count() != 0) {
         return true;
     }
     return false;
 }
开发者ID:warlof,项目名称:slackbot,代码行数:17,代码来源:AbstractSlack.php

示例4: match

 public function match(array $models, Collection $results, $relation)
 {
     $match = $this->matchPHP;
     foreach ($models as $model) {
         $value = $results->filter(function ($result) use($match, $model) {
             return $match($model, $result);
         });
         if ($value->count()) {
             $model->setRelation($relation, $value);
         }
     }
     return $models;
 }
开发者ID:jhaut,项目名称:eloquent-enhanced,代码行数:13,代码来源:RelatedToMany.php

示例5: getRoles

 /**
  * Get all roles as collection.
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function getRoles()
 {
     if (!$this->roles) {
         $this->roles = $this->grantedRoles()->get();
         $deniedRoles = $this->deniedRoles()->get();
         foreach ($deniedRoles as $role) {
             $deniedRoles = $deniedRoles->merge($role->descendants());
         }
         foreach ($this->roles as $role) {
             if (!$deniedRoles->contains($role)) {
                 $this->roles = $this->roles->merge($role->descendants());
             }
         }
         $this->roles = $this->roles->filter(function ($role) use($deniedRoles) {
             return !$deniedRoles->contains($role);
         });
     }
     return $this->roles;
 }
开发者ID:askedio,项目名称:laravelcp,代码行数:24,代码来源:HasRoleAndPermission.php

示例6: match

 /**
  * Match the eagerly loaded results to their parents.
  *
  * @param  array   $models
  * @param  \Illuminate\Database\Eloquent\Collection  $results
  * @param  string  $relation
  * @return array
  */
 public function match(array $models, Collection $results, $relation)
 {
     // We will need the parent node placeholder so that we use it to extract related results.
     $parent = $this->query->getQuery()->modelAsNode($this->parent->getTable());
     /**
      * Looping into all the parents to match back onto their children using
      * the primary key to map them onto the correct instances, every single
      * result will be having both instances at each Collection item, held by their
      * node placeholder.
      */
     foreach ($models as $model) {
         $matched = $results->filter(function ($result) use($parent, $model) {
             if ($result[$parent] instanceof Model) {
                 // In the case of fetching nested relations, we will get an array
                 // with the first key being the model we need, and the other being
                 // the related model so we'll just take the first model out of the array.
                 if (is_array($model)) {
                     $model = reset($model);
                 }
                 return $model->getKey() == $result[$parent]->getKey();
             }
         });
         // Now that we have the matched parents we know where to add the relations.
         // Sometimes we have more than a match so we gotta catch them all!
         foreach ($matched as $match) {
             // In the case of fetching nested relations, we will get an array
             // with the first key being the model we need, and the other being
             // the related model so we'll just take the first model out of the array.
             if (is_array($model)) {
                 $model = reset($model);
             }
             $model->setRelation($relation, $match[$relation]);
         }
     }
     return $models;
 }
开发者ID:sgpatil,项目名称:neoeloquent,代码行数:44,代码来源:OneRelation.php

示例7: getRecordForFile

 /**
  * Search through the record list for one matching the provided path.
  * @param  string $path
  * @param  \Illuminate\Database\Eloquent\Collection $existing_media
  * @return \Plank\Mediable\Media|null
  */
 protected function getRecordForFile($path, $existing_media)
 {
     $directory = File::cleanDirname($path);
     $filename = pathinfo($path, PATHINFO_FILENAME);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     return $existing_media->filter(function (Media $media) use($directory, $filename, $extension) {
         return $media->directory == $directory && $media->filename == $filename && $media->extension == $extension;
     })->first();
 }
开发者ID:plank,项目名称:laravel-mediable,代码行数:15,代码来源:ImportMediaCommand.php

示例8: handle

 /**
  * Execute the job.
  *
  * @return Collection
  */
 public function handle()
 {
     return $this->bookings->filter(function ($booking) {
         return !$booking->payment->count() ? true : false;
     })->sortByDesc('id');
 }
开发者ID:ChristianEGOL,项目名称:reisen-lizenz-tool-payment,代码行数:11,代码来源:BookingUnpayedJob.php

示例9: matchOneOrMany

 /**
  * Match the eagerly loaded results to their parents.
  *
  * @param  array   $models
  * @param  \Illuminate\Database\Eloquent\Collection  $results
  * @param  string  $relation
  * @return array
  */
 public function matchOneOrMany(array $models, Collection $results, $relation, $type)
 {
     // We will need the parent node placeholder so that we use it to extract related results.
     $parent = $this->query->getQuery()->modelAsNode($this->parent->getTable());
     /**
      * Looping into all the parents to match back onto their children using
      * the primary key to map them onto the correct instances, every single
      * result will be having both instances at each Collection item, held by their
      * node placeholder.
      */
     foreach ($models as $model) {
         $matched = $results->filter(function ($result) use($parent, $relation, $model) {
             if ($result[$parent] instanceof Model) {
                 return $model->getKey() == $result[$parent]->getKey();
             }
         });
         // Now that we have the matched parents we know where to add the relations.
         // Sometimes we have more than a match so we gotta catch them all!
         foreach ($matched as $match) {
             if ($type == 'many') {
                 $collection = $model->getRelation($relation);
                 $collection->push($match[$relation]);
                 $model->setRelation($relation, $collection);
             } else {
                 $model->setRelation($relation, $match[$relation]);
             }
         }
     }
     return $models;
 }
开发者ID:MethyleneGaming,项目名称:NeoEloquent,代码行数:38,代码来源:HasOneOrMany.php

示例10: getByAttributeFromCollection

 /**
  * Get items from collection whose properties match a given attribute and value
  *
  * @param  Collection  $collection
  * @param  string      $attribute
  * @param  mixed       $value
  *
  * @return Collection
  */
 protected function getByAttributeFromCollection(Collection $collection, $attribute, $value = null)
 {
     return $collection->filter(function ($item) use($attribute, $value) {
         if (isset($item->{$attribute}) && $value) {
             return $item->{$attribute} == $value;
         }
         return false;
     });
 }
开发者ID:stevenmaguire,项目名称:laravel-cache,代码行数:18,代码来源:EloquentCacheTrait.php

示例11: filterUnviewableForums

 /**
  * Filters a forum collection by the "canView" permission
  *
  * @param Collection $forums
  *
  * @return Collection
  */
 private function filterUnviewableForums(Collection $forums)
 {
     return $forums->filter(function (Forum $forum) {
         return $this->permissionChecker->hasPermission('forum', $forum->getContentId(), $forum::getViewablePermission(), $this->guard->user());
     });
 }
开发者ID:Adamzynoni,项目名称:mybb2,代码行数:13,代码来源:CachingDecorator.php

示例12: transformPost

 public function transformPost(\Post $post, Collection $favorites, Collection $subscriptions)
 {
     $response = ['id' => $post->id, 'text' => $post->text, 'created_at' => $post->created_at, 'updated_at' => $post->updated_at, 'user' => $this->transformUserToSmall($post->user), 'attachments' => $this->transformAttachments($post), 'comments_count' => $post->comments->count(), 'likes' => $post->likes->count(), 'commented' => $post->commented(), 'liked' => $post->liked() ? 1 : 0, 'is_fav' => $favorites->filter(function ($favorite) use($post) {
         return $favorite->id == $post->id;
     })->count() == 1 ? 1 : 0, 'category' => ['id' => $post->category->id, 'title' => $post->category->title, 'subscribed' => $subscriptions->filter(function ($subscription) use($post) {
         return $subscription->id == $post->category->id;
     })->count() == 1 ? 1 : 0]];
     //		if ($comments)
     //			$response['comments'] = $this->transformComments($post->comments);
     return $response;
 }
开发者ID:SenhorBardell,项目名称:yol,代码行数:11,代码来源:collectionTransformer.php

示例13: siblingOfRoot

 /**
  * Check if node is sibling for roots in collection
  *
  * @param Tree       $node  Tree node
  * @param Collection $roots Collection of roots
  *
  * @return bool
  */
 private function siblingOfRoot(Tree $node, Collection $roots)
 {
     return (bool) $roots->filter(function ($item) use($node) {
         return $node->isSibling($item);
     })->first();
 }
开发者ID:jimmygle,项目名称:eloquent-tree,代码行数:14,代码来源:Tree.php

示例14: returnProjectModels

 public function returnProjectModels(Collection $collection)
 {
     $user = \Authorization::user();
     $wishlist = WishModel::where('user_id', '=', $user->id)->get();
     if ($user->userable_type == BuyerModel::class) {
         $collection->filter(function ($item) use($wishlist) {
             $wishlist->contains('project_id', $item->id) ? $item->wishlisted = true : ($item->wishlisted = false);
             return $item;
         });
     }
     return $this->withCollection($collection, new ProjectTransformer());
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:12,代码来源:ProjectController.php

示例15: getFormingGuilds

 /**
  * Retrieve all the forming guilds.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $guilds
  * @return array
  */
 protected function getFormingGuilds(Collection $guilds)
 {
     return $guilds->filter(function ($guild) {
         return $guild->isForming();
     });
 }
开发者ID:apolune,项目名称:guilds,代码行数:12,代码来源:OverviewController.php


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