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


PHP Collection::unique方法代码示例

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


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

示例1: makeCollection

 /**
  * Make collection of value objects.
  *
  * @param array $items
  *
  * @return Collection
  */
 protected function makeCollection(array $items)
 {
     $objects = new Collection();
     foreach ($items as $item) {
         $objects->push(new $this->valueObject($item));
     }
     return $this->unique ? $objects->unique() : $objects;
 }
开发者ID:antennaio,项目名称:laravel-vo,代码行数:15,代码来源:ValueObjectCollection.php

示例2: getFromIds

 public function getFromIds(Collection $idCollection, $method, $force = false)
 {
     if ($idCollection->isEmpty()) {
         return $idCollection;
     }
     return $idCollection->unique()->map(function ($item, $key) use($force, $method) {
         return call_user_func([$this, $method], $item, $force);
     });
 }
开发者ID:Gamespectre,项目名称:spectator-api,代码行数:9,代码来源:ApiService.php

示例3: summary

 public function summary(Request $request, $regionId)
 {
     $region = Region::find($regionId);
     $user = false;
     $token = $request->header('Authorization');
     if ($token) {
         if (isset($token[1])) {
             $token = explode(' ', $request->header('Authorization'))[1];
             $payload = (array) JWT::decode($token, Config::get('app.token_secret'), array('HS256'));
             $user = User::find($payload['sub']);
         }
     }
     $participants = new Collection();
     $past_competitions = new Collection();
     $next_competitions = new Collection();
     $next_competition = array();
     $competitions = array();
     if ($regionId == 1) {
         $competitions = Competition::all();
         $videos = DB::table('medias')->where('region_id', '<>', $region->id)->get();
         $region->competitions = $competitions;
     } else {
         $competitions = $region->competitions;
         $videos = DB::table('medias')->where('region_id', '=', $region->id)->get();
     }
     $competitions->each(function ($competition) use($past_competitions, $next_competitions, $participants, $user) {
         $competition->users->each(function ($participant) use($participants, $competition, $user) {
             if ($user && $user->id == $participant->id) {
                 $competition->already_participating = true;
             }
             $participant->medias;
             $participant->competitions;
             $participants->push($participant);
         });
         $competition->location;
         $competition->videos;
         if (Carbon::now()->gte($competition->event_date)) {
             $competition->past = true;
             $past_competitions->push($competition);
         } else {
             $competition->past = false;
             $next_competitions->push($competition);
         }
     });
     $region->next_competition = $next_competitions->first();
     $region->next_competitions = $next_competitions;
     $region->past_competitions = $past_competitions;
     $region->videos = $videos;
     $region->videos_count = count($videos);
     $region->competitions_count = count($competitions);
     $region->participants = $participants->unique();
     $region->participants_count = count($region->participants);
     return $region;
 }
开发者ID:Coperable,项目名称:slam_webapp,代码行数:54,代码来源:RegionController.php

示例4: visible_bookmarks_count

 public function visible_bookmarks_count()
 {
     $this_tag_name = $this->name;
     $bookmarks = new Collection();
     $all_bookmarks = Bookmark::where('user_id', '=', Auth::user()->id)->orWhere('private', '=', false)->get();
     //iterate through all of the potential bookmarks
     foreach ($all_bookmarks as $bookmark) {
         $tags = $bookmark->tags()->get();
         foreach ($tags as $tag) {
             if ($tag->name == $this_tag_name) {
                 //user is allowed to see this one so add to collection
                 $bookmarks->push($bookmark);
                 break;
             }
         }
     }
     //done
     return $bookmarks->unique('id')->count();
 }
开发者ID:jjcosgrove,项目名称:laravel-bookmarks,代码行数:19,代码来源:Tag.php

示例5: addUseStatements

 /**
  * @return $this
  */
 private function addUseStatements()
 {
     if ($this->endpoint->count() > 1) {
         $this->uses->push(new ReflectionClass(Endpoint::class));
     }
     $unique = $this->uses->unique();
     $aliases = new Collection();
     $unique->each(function ($useStatement) use($aliases) {
         /** @var ReflectionClass $useStatement */
         $parent = $useStatement->getParentClass();
         if ($parent !== false && $parent->getName() === AbstractRequest::class) {
             $aliases->push($useStatement->getName() . " as " . $useStatement->getShortName() . "Request");
         } else {
             $aliases->push($useStatement->getName());
         }
     });
     if ($aliases->count() > 0) {
         $uses = $aliases->implode(";\nuse ");
         $this->out->writeln("Adding use statements to template");
         return $this->writeInTemplate("use_statements", "use " . $uses . ";");
     }
     return $this;
 }
开发者ID:ValentinGot,项目名称:trakt-api-wrapper,代码行数:26,代码来源:EndpointGenerator.php

示例6: unique

 /**
  * Return only unique items from the collection.
  *
  * @param  string|callable|null  $key
  * @return static
  */
 public function unique($key = null)
 {
     if (!is_null($key)) {
         return parent::unique($key);
     }
     return new static(array_values($this->getDictionary()));
 }
开发者ID:mubassirhayat,项目名称:Laravel51-starter,代码行数:13,代码来源:Collection.php

示例7: testUniqueWithCallback

 public function testUniqueWithCallback()
 {
     $c = new Collection([1 => ['id' => 1, 'first' => 'Taylor', 'last' => 'Otwell'], 2 => ['id' => 2, 'first' => 'Taylor', 'last' => 'Otwell'], 3 => ['id' => 3, 'first' => 'Abigail', 'last' => 'Otwell'], 4 => ['id' => 4, 'first' => 'Abigail', 'last' => 'Otwell'], 5 => ['id' => 5, 'first' => 'Taylor', 'last' => 'Swift'], 6 => ['id' => 6, 'first' => 'Taylor', 'last' => 'Swift']]);
     $this->assertEquals([1 => ['id' => 1, 'first' => 'Taylor', 'last' => 'Otwell'], 3 => ['id' => 3, 'first' => 'Abigail', 'last' => 'Otwell']], $c->unique('first')->all());
     $this->assertEquals([1 => ['id' => 1, 'first' => 'Taylor', 'last' => 'Otwell'], 3 => ['id' => 3, 'first' => 'Abigail', 'last' => 'Otwell'], 5 => ['id' => 5, 'first' => 'Taylor', 'last' => 'Swift']], $c->unique(function ($item) {
         return $item['first'] . $item['last'];
     })->all());
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:8,代码来源:SupportCollectionTest.php


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