當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::toArray方法代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Collection::toArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::toArray方法的具體用法?PHP Collection::toArray怎麽用?PHP Collection::toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Database\Eloquent\Collection的用法示例。


在下文中一共展示了Collection::toArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: insertAllRow

 protected function insertAllRow($sheet)
 {
     $sheet->each(function ($row) {
         $data = $this->parseFilm($row);
         $data['genre_id'] = $this->findGenreId($row['genero'], $data['title']);
         $film = $this->film->create($data);
         $country_id = $this->findCountryId($row['pais'], $film);
         $film->countries()->sync($country_id);
     });
     if (!$this->newGenres->isEmpty()) {
         $this->info(Lang::get('commands.iffe.new-genres-added'));
         $this->info(implode(',', $this->newGenres->toArray()));
     }
 }
開發者ID:filmoteca,項目名稱:filmoteca,代碼行數:14,代碼來源:ImportFilmsFromExcelCommand.php

示例2: cachePhotos

 /**
  *
  * Cache photos if caching is enabled
  *
  * @param Collection $photos
  */
 protected function cachePhotos($photos)
 {
     $cache = $this->property('cacheLifetime');
     if ($cache) {
         Cache::put('photoalbums_random_photos', $photos->toArray(), $cache);
     }
 }
開發者ID:graker,項目名稱:photoalbums,代碼行數:13,代碼來源:RandomPhotos.php

示例3: getRawCollectionData

 private function getRawCollectionData(Collection $collection)
 {
     foreach ($collection as $element) {
         $this->execute_with_relations ? $element->loadDisplayableRelations() : null;
     }
     return $collection->toArray();
 }
開發者ID:martinsv,項目名稱:JsonApi,代碼行數:7,代碼來源:DataHandler.php

示例4: createData

 /**
  * @param Collection $model
  * @param string $single
  *
  * @return string
  */
 public function createData($model, string $single)
 {
     $str = sprintf("\n\t\t\$scope.%s = new Minute.Models.%sArray(null);\n", $single, $this->fixName($single));
     $str .= sprintf("\t\t\$scope.%s.load(%s);\n", $single, json_encode($model->toArray(), JSON_PRETTY_PRINT));
     //{metadata: {offset: 0, limit: 2, total: %d}, items: %s}
     return $str;
 }
開發者ID:minutephp,項目名稱:framework,代碼行數:13,代碼來源:ModelJs.php

示例5: cachePosts

 /**
  *
  * Cache posts if caching is enabled
  *
  * @param Collection $posts
  */
 protected function cachePosts($posts)
 {
     $cache = $this->property('cacheLifetime');
     if ($cache) {
         Cache::put('blogarchive_random_posts', $posts->toArray(), $cache);
     }
 }
開發者ID:graker,項目名稱:blogarchive,代碼行數:13,代碼來源:RandomPosts.php

示例6: collectionAsItem

 public static function collectionAsItem(Collection $collection, array $columns, $cache = null)
 {
     $output = [];
     foreach ($collection->toArray() as $row) {
         $output[] = ['value' => isset($columns['value']) ? $row[$columns['value']] : $row['id'], 'text' => $row[$columns['text']]];
     }
     return $output;
 }
開發者ID:stanmay,項目名稱:unflare,代碼行數:8,代碼來源:Database.php

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

示例8: testToArrayCallsToArrayOnEachItemInCollection

 public function testToArrayCallsToArrayOnEachItemInCollection()
 {
     $item1 = m::mock('stdClass');
     $item1->shouldReceive('toArray')->once()->andReturn('foo.array');
     $item2 = m::mock('stdClass');
     $item2->shouldReceive('toArray')->once()->andReturn('bar.array');
     $c = new Collection(array($item1, $item2));
     $results = $c->toArray();
     $this->assertEquals(array('foo.array', 'bar.array'), $results);
 }
開發者ID:hochanh,項目名稱:Bootsoft-Bowling,代碼行數:10,代碼來源:EloquentCollectionTest.php

示例9: toApiArray

 public function toApiArray($type = null)
 {
     $collection = parent::toArray();
     $collectionCount = count($collection);
     for ($i = 0; $i < $collectionCount; $i++) {
         switch ($type) {
             case 'notebooks':
                 break;
         }
     }
     return $collection;
 }
開發者ID:Liongold,項目名稱:paperwork,代碼行數:12,代碼來源:paperworkCollection.php

示例10: toArray

 /**
  * Extending toArray.
  * Passing attribute you can get only an array of that elements from the collection models.
  *
  * @param string $attribute
  *
  * @return array
  */
 public function toArray($attribute = null)
 {
     $elements = parent::toArray();
     if (!$attribute) {
         return $elements;
     }
     $filtered = [];
     foreach ($elements as $element) {
         $filtered[] = $element[$attribute];
     }
     return $filtered;
 }
開發者ID:softsolution,項目名稱:antVel,代碼行數:20,代碼來源:Collection.php

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

示例12: addRowsFromCollection

 /**
  * Using the toArray() method of the collection, adds as rows to the datatable.
  * Columns must be added with the generic addColumn() method to define the model
  * property for the column id.
  * Stolen from kevinkhill/datatableplus.
  *
  * @param Collection $collection Collection of models
  *
  * @return self
  */
 public function addRowsFromCollection(Collection $collection)
 {
     $row = [];
     $colCount = $this->lavaDataTable->getColumnCount();
     foreach ($collection->toArray() as $collectionRow) {
         $row = [];
         for ($i = 0; $i < $colCount; $i++) {
             $row[] = $collectionRow[array_keys($collectionRow)[$i]];
         }
         $this->lavaDataTable->addRow($row);
     }
     return $row;
 }
開發者ID:Bogstag,項目名稱:bogstag.se,代碼行數:23,代碼來源:ChartController.php

示例13: familiars

 /**
  * Show the form for creating a new resource.
  *
  *
  */
 public function familiars(Request $request)
 {
     $depth = $request->query('n', 1);
     $neo4j = DB::connection('neo4j');
     /** @var $neo4j Connection */
     $client = $neo4j->getClient();
     /** @var $client Client */
     //Знаю что так нельзя, но нормально параметр вставить у меня не получилось - матюкается neo4j
     $cql = 'MATCH (x:users)-[friendship*' . $depth . ']-(y) WHERE id(x) = {id} RETURN y';
     $query = new Query($client, $cql, ['id' => Auth::user()->id]);
     $result = $query->getResultSet();
     $results = new Collection();
     foreach ($result as $row) {
         /** @var $row Row */
         $results->add(new User($row['y']->getProperties()));
     }
     return response()->json(['items' => $results->toArray()]);
 }
開發者ID:fun4life1990,項目名稱:friends,代碼行數:23,代碼來源:FriendController.php

示例14: save

 /**
  *
  */
 public function save()
 {
     if (empty($this->data)) {
         return;
     }
     if ($this->relation instanceof Relations\HasMany && is_array($this->data)) {
         if (is_numeric($this->data[0])) {
             $data = new Collection();
             foreach ($this->data as $key => $item) {
                 // $this->data[$key] = $this->related->baseModel->find($item);
                 $data->push($this->related->baseModel->find($item));
             }
         } else {
             $data = new Collection($this->data);
         }
         // detach any existing models and only save the selected ones
         $foreignKey = $this->relation->getPlainForeignKey();
         $current = $this->relation->getResults();
         if (!$current) {
             $this->relation->saveMany($data->toArray());
             return;
         }
         $all = $data->merge($current);
         foreach ($all as $item) {
             if ($keep = $data->find($item->getKey())) {
                 $this->relation->save($keep);
             } else {
                 $item->{$foreignKey} = null;
                 $item->save();
             }
         }
     } else {
         if ($this->relation instanceof Relations\BelongsToMany && is_array($this->data)) {
             if (is_numeric($this->data[0])) {
                 $this->relation->sync($this->data);
             }
         } else {
             /* If we have an id let's grab the model instance, otherwise assume we were given it */
             $this->data = is_numeric($this->data) ? $this->related->baseModel->find($this->data) : $this->data;
             parent::saveRelation($this->relation, $this->data);
         }
     }
 }
開發者ID:packettide,項目名稱:bree,代碼行數:46,代碼來源:Relate.php

示例15: var_set

 /**
  * Create recombined array with set fields
  *
  * @param Collection $data
  */
 public static function var_set(Collection $data)
 {
     $collection = new EloquentCollection();
     $model = get_class($data->first());
     foreach ($data as $item) {
         $origin = static::arrayValuesToString($item->getOriginal());
         $new = [];
         foreach ($model::$export_fields as $field => $properties) {
             if (isset($properties['relation'])) {
                 $method = $properties['relation']['method'];
                 $display = isset($properties['relation']['display']) ? $properties['relation']['display'] : null;
                 $new[] = static::getRelationItems($item, $method, $display);
             } else {
                 $new[] = $item->{$field};
             }
         }
         $collection->add($new);
     }
     return $collection->toArray();
 }
開發者ID:flo5581,項目名稱:larabackend,代碼行數:25,代碼來源:Recombinator.php


注:本文中的Illuminate\Database\Eloquent\Collection::toArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。