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


PHP Collection::first方法代码示例

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


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

示例1: setUnitsCollection

 /**
  * @param $imei
  * @param Collection|null $traza
  * @return array
  */
 private function setUnitsCollection($imei, Collection $traza = null, Collection $modeloInfo = null)
 {
     $result = [];
     if (!$traza == null) {
         return $result = ['imei' => $imei, 'sl' => $traza->first()->Codigo, 'fechaHora' => $traza->first()->FechaHora, 'carrier' => $this->findInCollection($modeloInfo, 'Campo', 'CARRIER')->Valor, 'salesModel' => $this->findInCollection($modeloInfo, 'Campo', 'SALESMODEL')->Valor, 'partNumber' => $this->findInCollection($modeloInfo, 'Campo', 'PART_NUMBER')->Valor];
     } else {
         return $result = ['imei' => $imei, 'sl' => 'Sin resultados', 'fechaHora' => '-', 'carrier' => '-', 'salesModel' => '-', 'partNumber' => '-'];
     }
 }
开发者ID:julioalpa,项目名称:MotorolaSL,代码行数:14,代码来源:HomeController.php

示例2: upload

 public function upload(PhotoUploadRequest $request)
 {
     $user = Auth::user();
     $destinationPath = 'uploads/';
     if ($request->hasFile('files')) {
         $photos = new Collection();
         $i = 0;
         foreach ($request->file('files') as $file) {
             $extension = $file->getClientOriginalExtension();
             $new_filename = time() . uniqid() . str_random(rand(5, 15)) . '.' . $extension;
             $file->move($destinationPath, $new_filename);
             $photos[$i] = new Photo();
             $photos[$i]->content_type = $file->getClientMimeType();
             $photos[$i]->disk_name = $new_filename;
             $photos[$i]->file_name = $file->getClientOriginalName();
             $photos[$i]->path = $destinationPath . $new_filename;
             $photos[$i]->file_size = $file->getClientSize();
             $photos[$i]->user_id = $user->id;
             $photos[$i]->save();
             $i++;
         }
         return $photos->first();
     }
     return response()->json(['status' => 'error']);
 }
开发者ID:devillom,项目名称:simpleshop,代码行数:25,代码来源:PhotoController.php

示例3: formatEloquentCollection

 /**
  * Format an Eloquent collection.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $collection
  * @return string
  */
 public function formatEloquentCollection($collection)
 {
     if ($collection->isEmpty()) {
         return $this->encode([]);
     }
     $key = str_plural($collection->first()->getTable());
     return $this->encode([$key => $collection->toArray()]);
 }
开发者ID:andymrussell,项目名称:api,代码行数:14,代码来源:JsonResponseFormat.php

示例4: shouldTryAgain

 /**
  * shouldTryAgain.
  *
  * @author Casper Rasmussen <cr@nodes.dk>
  * @return bool
  */
 private function shouldTryAgain()
 {
     if ($this->failedCarbons->count() < $this->maxNetworkRetries) {
         return true;
     }
     /** @var Carbon $carbon */
     $carbon = $this->failedCarbons->first();
     if ($carbon->diffInSeconds(Carbon::now()) >= $this->retryNetworkAfterSec) {
         return true;
     }
     return false;
 }
开发者ID:nodes-php,项目名称:translate,代码行数:18,代码来源:NStack.php

示例5: formatEloquentCollection

 /**
  * Format an Eloquent collection.
  *
  * @param \Illuminate\Database\Eloquent\Collection $collection
  *
  * @return string
  */
 public function formatEloquentCollection($collection)
 {
     if ($collection->isEmpty()) {
         return $this->encode([]);
     }
     $model = $collection->first();
     $key = str_plural($model->getTable());
     if (!$model::$snakeAttributes) {
         $key = camel_case($key);
     }
     return $this->encode([$key => $collection->toArray()]);
 }
开发者ID:joselfonseca,项目名称:api,代码行数:19,代码来源:Json.php

示例6: match

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

示例7: generateArrayData

 /**
  * @param \Illuminate\Database\Eloquent\Collection|static[] $collection
  */
 public function generateArrayData($collection)
 {
     $modelObject = $collection->first();
     $arrayData = array();
     foreach ($collection as $item) {
         $row = array();
         foreach ($modelObject->getListAttributes() as $index => $value) {
             $row[] = $item->{$index};
         }
         $pk = $modelObject->getPrimaryKey();
         $href = route('admin_edit', ['model' => $this->model->getUrlName(), 'id' => "{$pk}:{$item->{$pk}}"]);
         $row[] = "<a href='{$href}'>Editar</a>";
         $arrayData[] = $row;
     }
     return $arrayData;
 }
开发者ID:albafo,项目名称:web.MagickLaravel,代码行数:19,代码来源:ModelListComposer.php

示例8: extractModelAndKeys

 /**
  * Extract the model instance and model keys from the given parameters.
  *
  * @param  string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection  $model
  * @param  array|null  $keys
  * @return array
  */
 public static function extractModelAndKeys($model, array $keys = null)
 {
     if (is_null($keys)) {
         if ($model instanceof Model) {
             return [$model, [$model->getKey()]];
         }
         if ($model instanceof Collection) {
             return [$model->first(), $model->modelKeys()];
         }
     } else {
         if (is_string($model)) {
             $model = new $model();
         }
         return [$model, $keys];
     }
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:23,代码来源:Helper.php

示例9: getMeta

 /**
  * Gets meta data
  *
  * @param string $key
  * @param null|mixed $default
  * @param bool $raw
  * @return Collection
  */
 public function getMeta($key, $default = null, $raw = false)
 {
     $meta = $this->meta()->where('key', $key)->get();
     if ($raw) {
         $collection = $meta;
     } else {
         $collection = new Collection();
         foreach ($meta as $m) {
             $collection->put($m->id, $m->value);
         }
     }
     if (0 == $collection->count()) {
         return $default;
     }
     return $collection->count() <= 1 ? $collection->first() : $collection;
 }
开发者ID:AlexanderPoellmann,项目名称:laravel-meta,代码行数:24,代码来源:HasMeta.php

示例10: showProspects

 /**
  * Display one or more prospects.
  *
  * @note We're using the 'table()' function which expects an array
  *       of arrays (i.e. rows of data items/fields)
  *
  * @param Collection $prospects
  * @param bool $forceList
  * @param int $maxLen
  */
 protected function showProspects($prospects, $forceList = false, $maxLen = 76)
 {
     if (empty($prospects) || $prospects->isEmpty()) {
         $this->info('No prospect records to display');
         return;
     }
     if ($prospects->count() > 1 || $forceList) {
         $rows = $prospects->toArray();
         $this->table(array_keys($rows[0]), $rows);
     } else {
         $prospect = $prospects->first();
         $data = $prospect->toArray();
         $rows = [];
         foreach ($data as $k => $v) {
             $rows[] = [$k, is_string($v) ? str_limit($v, $maxLen) : $v];
         }
         $this->table(['field', 'value'], $rows);
     }
     $this->info('');
     // Print a blank line
 }
开发者ID:mlanser,项目名称:prospect-mgr,代码行数:31,代码来源:ProspectCommandTrait.php

示例11: nenaplaceno

 /**
  * Odgovor servera u slučaju pokušaja rezerviranja kada postoje nenaplaćene rezervacije.
  * @param \Illuminate\Database\Eloquent\Collection $nenaplaceneRezervacije Nenaplaćene rezervacije
  * @return Response
  */
 private function nenaplaceno($nenaplaceneRezervacije)
 {
     Session::flash(self::DANGER_MESSAGE_KEY, 'Nije dozvoljeno praviti rezervaiju dok ne naplatite sve odrađene.<br/>' . 'Primjerice rezervacija ' . $nenaplaceneRezervacije->first()->link() . ' nije naplaćena.');
     return Redirect::route('home');
 }
开发者ID:Firtzberg,项目名称:Edu,代码行数:10,代码来源:RezervacijaController.php

示例12: testFirstReturnsFirstItemInCollection

 public function testFirstReturnsFirstItemInCollection()
 {
     $c = new Collection(array('foo', 'bar'));
     $this->assertEquals('foo', $c->first());
 }
开发者ID:hochanh,项目名称:Bootsoft-Bowling,代码行数:5,代码来源:EloquentCollectionTest.php

示例13: findProductItem

 /**
  * Find the item entry of a specific product key in a collection of items.
  *
  * @param  \Illuminate\Database\Eloquent\Collection $items
  * @param  mixed                                    $key   The product's primary key.
  *
  * @return \REDACTED\Wastage\ItemModel|null
  */
 protected function findProductItem(Collection $items, $key)
 {
     if ($key instanceof ItemModel) {
         $key = $key->getKey();
     }
     return $items->first(function ($id, $item) use($key) {
         return $item->product_id == $key;
     });
 }
开发者ID:viniciusferreira,项目名称:laravel-repository,代码行数:17,代码来源:RealWorldExample.php

示例14: first

 public function first()
 {
     return $this->data->first();
 }
开发者ID:minutephp,项目名称:framework,代码行数:4,代码来源:UserInfoTest.php

示例15: updateUserHashtags

 /**
  * Updates the current user's searched hashtags with the specified hashtag
  * $terms and returns the number of hashtags updated or -1 on failure.
  *
  * @param  Collection   $hashtags hashtag collection to update
  * @param  array|string $terms hashtag terms to update with
  * @return integer
  */
 protected function updateUserHashtags(Collection $hashtags, array $terms)
 {
     $num_updates = 0;
     foreach ($terms as $id => $term) {
         // remove whitespace, convert to lowercase
         $term = strtolower(preg_replace('/\\s+/', '', $term));
         if (!empty(trim($term))) {
             // verify hashtag term does not already exists
             $hashtag = $hashtags->first(function ($key, $value) use($id, $term) {
                 return $value->id != $id && $value->term == $term;
             });
             if (isset($hashtag)) {
                 // indicate error has occured
                 $num_updates = -1;
                 \Session::put('error_hashtag_edit_id', $id);
                 \Session::flash('flash_message', 'Hashtag \'' . $term . '\' already exists.');
                 break;
             }
             // update hashtag term if not the same
             $hashtag = $hashtags->find($id);
             if (isset($hashtag) && $hashtag->term != $term) {
                 $hashtag->term = $term;
                 $hashtag->save();
                 $num_updates++;
             }
         }
     }
     return $num_updates;
 }
开发者ID:jasonjyu,项目名称:cscie15-p4,代码行数:37,代码来源:HashtagController.php


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