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


PHP Collection::count方法代码示例

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


在下文中一共展示了Collection::count方法的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: createImportEntries

 /**
  * Run the actual import
  *
  * @return Collection
  */
 public function createImportEntries() : Collection
 {
     $config = $this->job->configuration;
     $content = $this->job->uploadFileContents();
     // create CSV reader.
     $reader = Reader::createFromString($content);
     $reader->setDelimiter($config['delimiter']);
     $start = $config['has-headers'] ? 1 : 0;
     $results = $reader->fetch();
     Log::notice('Building importable objects from CSV file.');
     foreach ($results as $index => $row) {
         if ($index >= $start) {
             $line = $index + 1;
             Log::debug('----- import entry build start --');
             Log::debug(sprintf('Now going to import row %d.', $index));
             $importEntry = $this->importSingleRow($index, $row);
             $this->collection->put($line, $importEntry);
             /**
              * 1. Build import entry.
              * 2. Validate import entry.
              * 3. Store journal.
              * 4. Run rules.
              */
             $this->job->addTotalSteps(4);
             $this->job->addStepsDone(1);
         }
     }
     Log::debug(sprintf('Import collection contains %d entries', $this->collection->count()));
     Log::notice(sprintf('Built %d importable object(s) from your CSV file.', $this->collection->count()));
     return $this->collection;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:36,代码来源:CsvImporter.php

示例3: setRelatedModelFields

 public function setRelatedModelFields(Collection $relations)
 {
     $this->setModelRelations($relations);
     if ($this->relations->count() > 0) {
         foreach ($this->relations as $relation) {
             if ($relation instanceof Collection) {
                 $this->addModelFields($relation->get('relation')->getEditFields());
             } else {
                 $this->addModelFields($relation->getEditFields());
             }
         }
     }
 }
开发者ID:anavel,项目名称:crud,代码行数:13,代码来源:Generator.php

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

示例5: clean

 /**
  * Clean collection by filling in all the blanks.
  */
 public function clean() : Collection
 {
     Log::notice(sprintf('Started validating %d entry(ies).', $this->entries->count()));
     $newCollection = new Collection();
     /** @var ImportEntry $entry */
     foreach ($this->entries as $index => $entry) {
         Log::debug(sprintf('--- import validator start for row %d ---', $index));
         /*
          * X Adds the date (today) if no date is present.
          * X Determins the types of accounts involved (asset, expense, revenue).
          * X Determins the type of transaction (withdrawal, deposit, transfer).
          * - Determins the currency of the transaction.
          * X Adds a default description if there isn't one present.
          */
         $entry = $this->checkAmount($entry);
         $entry = $this->setDate($entry);
         $entry = $this->setAssetAccount($entry);
         $entry = $this->setOpposingAccount($entry);
         $entry = $this->cleanDescription($entry);
         $entry = $this->setTransactionType($entry);
         $entry = $this->setTransactionCurrency($entry);
         $newCollection->put($index, $entry);
         $this->job->addStepsDone(1);
     }
     Log::notice(sprintf('Finished validating %d entry(ies).', $newCollection->count()));
     return $newCollection;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:30,代码来源:ImportValidator.php

示例6: setNamespace

 private function setNamespace()
 {
     $parts = clone $this->endpoint;
     $parts->pop();
     $namespace = $this->endpoint->count() === 1 ? $this->apiNamespace : $this->apiNamespace . '\\' . $parts->implode("\\");
     return $this->writeInTemplate("namespace", $namespace);
 }
开发者ID:ValentinGot,项目名称:trakt-api-wrapper,代码行数:7,代码来源:EndpointGenerator.php

示例7: paginateCollection

 /**
  * Paginates a collection. For simple pagination, one can override this function
  *
  * a little help from http://laravelsnippets.com/snippets/custom-data-pagination
  *
  * @param Collection $data
  * @param int $perPage
  * @param Request $request
  * @param null $page
  *
  * @return LengthAwarePaginator
  */
 public function paginateCollection(Collection $data, $perPage, Request $request, $page = null)
 {
     $pg = $request->get('page');
     $page = $page ? (int) $page * 1 : (isset($pg) ? (int) $request->get('page') * 1 : 1);
     $offset = $page * $perPage - $perPage;
     return new LengthAwarePaginator($data->splice($offset, $perPage), $data->count(), $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
 }
开发者ID:muhamadsyahril,项目名称:ecommerce-1,代码行数:19,代码来源:EloquentExtensions.php

示例8: request

 function tour_compare_add()
 {
     $id = request()->input('id');
     if ($id) {
         $query['id'] = $id;
         $query['with_travel_agent'] = true;
         $api_response = json_decode($this->api->get($this->api_url . '/tours?' . http_build_query(array_merge($query, ['access_token' => Session::get('access_token')])))->getBody());
         if ($api_response->data->data[0]) {
             $tour = $api_response->data->data[0];
             $comparison = session()->get('tour_comparison');
             if (!$comparison) {
                 $comparison = new Collection();
             }
             // Check if there's already max amount of comparable tour
             if ($comparison->count() >= 4) {
                 return response()->json(JSend::fail(['comparison' => 'Tidak dapat membandingkan lebih dari 4 paket tour'])->asArray());
             }
             // Make sure no duplicated tour
             if (!$comparison->where('_id', $tour->_id)->count()) {
                 $comparison->push($tour);
             }
             session()->put('tour_comparison', $comparison);
             return response()->json(JSend::success($comparison->toArray())->asArray());
         } else {
             return app::abort(404);
         }
     } else {
         return app()->abort(400);
     }
 }
开发者ID:erickmo,项目名称:capcusv3,代码行数:30,代码来源:APIController.php

示例9: addChoice

 /**
  * @param string|array $_choice
  * @param string       $_value
  *
  * @return $this
  */
 public function addChoice($_choice, $_value = null)
 {
     if (is_array($_choice)) {
         $text = array_get($_choice, 'label');
         $value = array_get($_choice, 'value');
         $atts = array_except($_choice, ['label']);
     } else {
         $text = $_choice;
         $value = is_null($_value) ? $_choice : $_value;
         $atts = ['value' => $value];
     }
     if (!isset($atts['id'])) {
         $atts['id'] = $this->id . '-' . $this->choices->count();
     }
     $choice = new Input($this->type, $this->name, $value, $atts);
     $choice->inputCheckable = true;
     $choice->setAttribute('type', $this->type);
     if ($this->isSelected($value)) {
         $choice->setAttribute('checked', 'checked');
     }
     $choice->addClass($this->type);
     $choice->setLabel($text);
     $choice->setContainer(null);
     $this->choices->push($choice);
     return $this;
 }
开发者ID:potterywp,项目名称:potter,代码行数:32,代码来源:Checkable.php

示例10: __construct

 /**
  * CollectionProvider constructor.
  * @param Collection $collection The collection with the initial data
  */
 public function __construct(Collection $collection)
 {
     $this->collection = $collection;
     $this->totalInitialDataCount = $collection->count();
     $this->setupSearch();
     $this->setupOrder();
 }
开发者ID:ReactionJordan,项目名称:Datatable,代码行数:11,代码来源:CollectionProvider.php

示例11: save

 protected function save()
 {
     $count_of_changes = $this->added->count() + $this->altered->count() + $this->deleted->count();
     $scan = new FileScan();
     $scan->changes = $count_of_changes;
     $scan->account_id = $this->account->id;
     $scan->save();
 }
开发者ID:joshwhatk,项目名称:super-scan,代码行数:8,代码来源:Scan.php

示例12: getMeta

 /**
  * Gets meta data
  *
  * @param $key
  * @param null $default
  * @param bool $getObj
  * @return Collection
  */
 public function getMeta($key, $default = null, $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);
         }
     }
     // Were there no records? Return NULL if no default provided
     if (0 == $collection->count()) {
         return $default;
     }
     return $collection->count() <= 1 ? $collection->first() : $collection;
 }
开发者ID:RonnyLV,项目名称:eloquent-meta,代码行数:25,代码来源:MetaTrait.php

示例13: getForumThreadsByTagsPaginated

 public function getForumThreadsByTagsPaginated(Collection $tags, $perPage = 20)
 {
     $query = $this->model->with(['slug', 'mostRecentChild', 'tags'])->where('type', '=', COMMENT::TYPE_FORUM)->join('comment_tag', 'comments.id', '=', 'comment_tag.comment_id');
     if ($tags->count() > 0) {
         $query->whereIn('comment_tag.tag_id', $tags->lists('id'));
     }
     $query->groupBy('comments.id')->orderBy('updated_at', 'desc');
     return $query->paginate($perPage, ['comments.*']);
 }
开发者ID:broklyngagah,项目名称:laravel.io,代码行数:9,代码来源:CommentRepository.php

示例14: postInstall

 /**
  * Handle the installation request.
  *
  * @param         $step
  * @param Request $request
  * @return mixed
  *
  * @author Cali
  */
 public function postInstall($step, Request $request)
 {
     $this->validateForm($step, $request);
     if ($step == 1) {
         $credentials = ['host' => $request->input('db_host'), 'database' => $request->input('db_name'), 'username' => $request->input('db_user'), 'password' => $request->input('db_password'), 'prefix' => $request->input('db_prefix')];
         if ($this->checkWritability()->checkDatabaseCredentials($credentials)) {
             File::put(base_path('step-1.lock'), '#');
         }
     } else {
         $credentials = ['email' => $request->input('admin_email'), 'username' => $request->input('admin_username'), 'password' => $request->input('admin_password')];
         $this->migrateAndCreateAdmin($credentials);
         return redirect(route('dashboard'));
     }
     if ($this->errorMessages->count()) {
         return redirect(route('install', compact('step'), false))->with(['status' => $this->buildErrorMessages(), 'succeeded' => 0]);
     }
     return redirect(route('install', compact('step'), false))->with(['status' => $this->getSuccessMessages($step), 'succeeded' => 1]);
 }
开发者ID:projnoah,项目名称:noah,代码行数:27,代码来源:InstallationController.php

示例15: getPrefixes

 /**
  * Search for any prefixes attached to this route.
  *
  * @return string
  */
 protected function getPrefixes()
 {
     $router = app(\Illuminate\Routing\Router::class);
     $this->prefixes = collect(explode('/', $router->getCurrentRoute()->getPrefix()));
     // Remove the last prefix if it matches the controller.
     $this->prefixes = $this->removeControllerFromPrefixes($this->prefixes);
     if ($this->prefixes->count() > 0) {
         $this->prefix = $this->prefixes->filter()->implode('.');
     }
 }
开发者ID:nukacode,项目名称:core,代码行数:15,代码来源:ViewModel.php


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