當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。