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


PHP Collection::first方法代码示例

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


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

示例1: getInitial

 public function getInitial()
 {
     $words = new Collection(explode(' ', $this->name));
     // if name contains single word, use first N character
     if ($words->count() === 1) {
         if ($this->name->length() >= $this->length) {
             return $this->name->substr(0, $this->length);
         }
         return (string) $words->first();
     }
     // otherwise, use initial char from each word
     $initials = new Collection();
     $words->each(function ($word) use($initials) {
         $initials->push(Stringy::create($word)->substr(0, 1));
     });
     return $initials->slice(0, $this->length)->implode('');
 }
开发者ID:explore-laravel,项目名称:avatar,代码行数:17,代码来源:InitialGenerator.php

示例2: getFirstWeapon

 /**
  * @return \Pipboy\Contracts\AbstractWeapon
  */
 public function getFirstWeapon()
 {
     if (is_null($this->items)) {
         return false;
     }
     return $this->items->first(function ($i, AbstractItem $item) {
         return !(strpos($item->getuid(), 'weapon') === false);
     });
 }
开发者ID:howlowck,项目名称:pipboy-unit,代码行数:12,代码来源:User.php

示例3: multiYear

 /**
  * @param Collection $entries
  *
  * @return array
  */
 public function multiYear(Collection $entries)
 {
     // dataset:
     $data = ['count' => 0, 'labels' => [], 'datasets' => []];
     // get labels from one of the categories (assuming there's at least one):
     $first = $entries->first();
     $keys = array_keys($first['spent']);
     foreach ($keys as $year) {
         $data['labels'][] = strval($year);
     }
     // then, loop all entries and create datasets:
     foreach ($entries as $entry) {
         $name = $entry['name'];
         $spent = $entry['spent'];
         $earned = $entry['earned'];
         if (array_sum(array_values($spent)) != 0) {
             $data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
         }
         if (array_sum(array_values($earned)) != 0) {
             $data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
         }
     }
     $data['count'] = count($data['datasets']);
     return $data;
 }
开发者ID:zjean,项目名称:firefly-iii,代码行数:30,代码来源:ChartJsCategoryChartGenerator.php

示例4: resolve

 /**
  * Determines a winner from the list of buzzes accumulated.
  *
  * Note: This method is destructive, and will clear the list of buzzes on completion.
  * @return BuzzerResolution
  */
 public function resolve()
 {
     if ($this->isEmpty()) {
         return BuzzerResolution::createFailure();
     }
     /** @var BuzzReceivedEvent $winner */
     $winner = $this->buzzes->reduce(function (BuzzReceivedEvent $carry, BuzzReceivedEvent $event) {
         if ($event->getDifference() < $carry->getDifference()) {
             return $event;
         }
         return $carry;
     }, $this->buzzes->first());
     $resolution = BuzzerResolution::createSuccess($winner->getContestant(), $winner->getDifference());
     $this->buzzes = new Collection();
     return $resolution;
 }
开发者ID:mattsches,项目名称:Jeopardy,代码行数:22,代码来源:Resolver.php

示例5: makeForCollection

 public static function makeForCollection(Collection $collection)
 {
     if ($collection->count() === 0) {
         throw new \OutOfRangeException("Requested collection does not contain any items");
     }
     return static::makeForModel($collection->first());
 }
开发者ID:efrane,项目名称:transfugio,代码行数:7,代码来源:TransformerFactory.php

示例6: __construct

 /**
  * @param Collection $collection
  * @param $request
  */
 public function __construct(Collection $collection, $request)
 {
     $this->collection = $collection;
     $this->original_collection = $collection;
     $this->columns = array_keys($this->serialize((array) $collection->first()));
     parent::__construct($request);
 }
开发者ID:Kirylka,项目名称:Scaffold,代码行数:11,代码来源:CollectionEngine.php

示例7: __construct

 /**
  * @param Collection $collection
  * @param \Yajra\Datatables\Request $request
  */
 public function __construct(Collection $collection, Request $request)
 {
     $this->request = $request;
     $this->collection = $collection;
     $this->original_collection = $collection;
     $this->columns = array_keys($this->serialize($collection->first()));
 }
开发者ID:marcha,项目名称:laravel-datatables,代码行数:11,代码来源:CollectionEngine.php

示例8: collectPermissions

 protected function collectPermissions($permission)
 {
     if (is_string($permission)) {
         $permission = app(PermissionContract::class)->whereSlug($permission)->first();
     }
     if (is_array($permission) or $permission instanceof Collection) {
         $permission = new Collection($permission);
         if (is_string($permission->first())) {
             return app(PermissionContract::class)->whereIn('slug', $permission->toArray())->get();
         } elseif ($permission->first() instanceof PermissionContract) {
             return $permission;
         }
     } elseif ($permission instanceof PermissionContract) {
         return $permission;
     }
     return null;
 }
开发者ID:znck,项目名称:trust,代码行数:17,代码来源:Role.php

示例9: handleDirectory

 /**
  * @param $properties
  * @param $content
  */
 private function handleDirectory(Collection $properties, $content)
 {
     $properties->push($content['filename']);
     $this->filesystem->createDir('Api/' . $this->endpoint->first());
     $generator = new EndpointGenerator($this->inputInterface, $this->out, $this->dialogHelper);
     $endpoint = str_replace("Request/", "", $content['path']);
     $generator->generateForEndpoint($endpoint);
 }
开发者ID:ValentinGot,项目名称:trakt-api-wrapper,代码行数:12,代码来源:EndpointGenerator.php

示例10: single

 /**
  * @param Collection $schedules
  * @return \Filmoteca\Models\Activity
  */
 public function single(Collection $schedules)
 {
     $activity = new Activity();
     $firstSchedule = $schedules->first();
     $film = $firstSchedule->exhibition->exhibition_film->film;
     $auditorium = $firstSchedule->auditorium;
     $activity->setId($film->id . $auditorium->id)->setTitle($firstSchedule->exhibition->exhibition_film->title)->setFacility($auditorium)->setPublicType('General')->setContact(self::getContact($firstSchedule))->setSchedules(Formatter::toDateTime($schedules))->setExtraSchedules(Formatter::toExtraTime($schedules))->setPrices(Formatter::toPrices($schedules))->setDiscounts(Formatter::toDiscounts($schedules))->setCommentaries($firstSchedule->exhibition->notes)->setCategory(self::CATEGORY)->setImage($film->image)->setReview($firstSchedule->exhibition->exhibition_film->film->synopsis);
     return $activity;
 }
开发者ID:filmoteca,项目名称:filmoteca,代码行数:13,代码来源:ActivityFactory.php

示例11: toArray

 /**
  * Get the instance as an array.
  *
  * @return array
  */
 public function toArray()
 {
     if ($this->channels instanceof Collection) {
         // 先拿到第一个子级频道项,并拿到它的父级频道ID
         // 开始遍历整个频道栏目,但是跳过第一条记录
         // 当然,每当遇到父级频道ID与当前频道ID相同
         // 则该为根级频道,一次搜索完成
         $first = $this->channels->first();
         $cursor = $first->channel_id;
         $iterator = $this->channels->getIterator();
         while ($iterator->valid() && ($channel = $iterator->current())) {
             echo 'prepare' . PHP_EOL;
             if ($channel->channel_id == $cursor || $channel->flag === 1) {
                 $iterator->next();
                 continue;
             }
             echo 'start' . PHP_EOL;
             var_dump($first->channel_id, $first->channel_parent);
             // 当一次搜索完成时,重新搜索数据集
             if (isset($_parent) && $_parent->channel_id === $_parent->channel_parent) {
                 echo 'rewind' . PHP_EOL;
                 $iterator->rewind();
                 continue;
             }
             if ($channel->channel_id === $first->channel_parent) {
                 $_parent = $channel;
                 echo 'merge' . PHP_EOL;
                 var_dump($_parent->channel_id);
                 $this->{$_parent->channel_type}[$_parent->channel_name] = array_merge($this->{$_parent->channel_type}, ['data' => $first, 'idx' => $cursor, 'to' => $_parent->channel_id]);
                 echo 'to wind' . PHP_EOL;
                 var_dump($this->{$_parent->channel_type});
                 // 因为已经设置过子父级关系,则当前数据项设置为1
                 $cursor = $_parent->channel_id;
                 $first = $_parent;
                 $channel->flag = 1;
             }
             echo 'complete' . PHP_EOL;
             $iterator->next();
         }
     }
     return array_merge(['default' => $this->default], ['mega' => $this->mega]);
 }
开发者ID:AInotamm,项目名称:Haku.moe,代码行数:47,代码来源:Channel.php

示例12: 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

示例13: getUserTrends

 public function getUserTrends(Collection $rounds)
 {
     $first = $rounds->first();
     $last = $rounds->last();
     $totalRounds = $rounds->count();
     $strokes = ($last->totalStrokes() - $first->totalStrokes()) / $totalRounds;
     $putts = ($last->totalPutts() - $first->totalPutts()) / $totalRounds;
     $strokesPar3 = ($last->totalStrokesPar(3) - $first->totalStrokesPar(3)) / $totalRounds;
     $strokesPar4 = ($last->totalStrokesPar(4) - $first->totalStrokesPar(4)) / $totalRounds;
     $strokesPar5 = ($last->totalStrokesPar(5) - $first->totalStrokesPar(5)) / $totalRounds;
     return compact('strokes', 'putts', 'strokesPar3', 'strokesPar4', 'strokesPar5');
 }
开发者ID:robeasdon,项目名称:golf-stat-tracker,代码行数:12,代码来源:UserRepository.php

示例14: getMeta

 /**
  * Gets meta data
  *
  * @return Illuminate\Support\Collection
  */
 public function getMeta($key, $getObj = false)
 {
     $meta = $this->meta()->where('key', $key)->get();
     if ($getObj) {
         $collection = $meta;
     } else {
         $collection = new Collection();
         foreach ($meta as $m) {
             $collection->put($m->id, $m->value);
         }
     }
     return $collection->count() <= 1 ? $collection->first() : $collection;
 }
开发者ID:kee-work,项目名称:scubaclick-meta,代码行数:18,代码来源:MetaTrait.php

示例15: update

 /**
  * @param \Illuminate\Support\Collection $collection
  * @param array                          $attributes
  *
  * @return bool|int|\WP_Error
  */
 public static function update(Collection $collection, $attributes = [])
 {
     $user = $collection->first();
     $attr = ['ID' => $user->ID];
     $self = new static();
     $attributes = $self->prepareFields($attributes, 'updating');
     $user_id = wp_update_user(array_merge($attributes, $attr));
     if (is_wp_error($user_id)) {
         return $user_id;
     }
     $self->addOrUpdateMetafields($user->ID, $attributes);
     return true;
 }
开发者ID:bruno-barros,项目名称:w.eloquent-helpers,代码行数:19,代码来源:User.php


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