collections
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| collections [2020/12/23 19:16] – создано chifek | collections [2023/09/14 06:06] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 12: | Line 12: | ||
| </ | </ | ||
| As you can see, the Collection class allows you to chain its methods to perform fluent mapping and reducing of the underlying array. In general, collections are immutable, meaning every Collection method returns an entirely new Collection instance. | As you can see, the Collection class allows you to chain its methods to perform fluent mapping and reducing of the underlying array. In general, collections are immutable, meaning every Collection method returns an entirely new Collection instance. | ||
| + | |||
| + | **Creating Collections** | ||
| + | |||
| + | As mentioned above, the collect helper returns a new Illuminate\Support\Collection instance for the given array. So, creating a collection is as simple as: | ||
| + | |||
| + | < | ||
| + | |||
| + | **Extending Collections** | ||
| + | |||
| + | Collections are " | ||
| + | < | ||
| + | use Illuminate\Support\Collection; | ||
| + | use Illuminate\Support\Str; | ||
| + | |||
| + | Collection:: | ||
| + | return $this-> | ||
| + | return Str:: | ||
| + | }); | ||
| + | }); | ||
| + | |||
| + | $collection = collect([' | ||
| + | |||
| + | $upper = $collection-> | ||
| + | |||
| + | // [' | ||
| + | </ | ||
| + | Typically, you should declare collection macros in the boot method of a service provider. | ||
| + | |||
| + | |||
| + | **Macro Arguments** | ||
| + | |||
| + | If necessary, you may define macros that accept additional arguments: | ||
| + | |||
| + | < | ||
| + | use Illuminate\Support\Collection; | ||
| + | use Illuminate\Support\Facades\Lang; | ||
| + | use Illuminate\Support\Str; | ||
| + | |||
| + | Collection:: | ||
| + | return $this-> | ||
| + | return Lang:: | ||
| + | }); | ||
| + | }); | ||
| + | |||
| + | $collection = collect([' | ||
| + | |||
| + | $translated = $collection-> | ||
| + | </ | ||
| + | |||
| + | **Available Methods** | ||
| + | |||
| + | For the majority of the remaining collection documentation, | ||
| + | |||
| + | |||
| + | all | ||
| + | |||
| + | average | ||
| + | |||
| + | avg | ||
| + | |||
| + | chunk | ||
| + | |||
| + | chunkWhile | ||
| + | |||
| + | collapse | ||
| + | |||
| + | collect | ||
| + | |||
| + | combine | ||
| + | |||
| + | |||
| + | concat | ||
| + | |||
| + | contains | ||
| + | |||
| + | containsStrict | ||
| + | |||
| + | count | ||
| + | |||
| + | countBy | ||
| + | |||
| + | crossJoin | ||
| + | |||
| + | dd | ||
| + | |||
| + | diff | ||
| + | |||
| + | |||
| + | |||
| + | diffAssoc | ||
| + | |||
| + | diffKeys | ||
| + | |||
| + | dump | ||
| + | |||
| + | duplicates | ||
| + | |||
| + | duplicatesStrict | ||
| + | |||
| + | each | ||
| + | |||
| + | eachSpread | ||
| + | |||
| + | every | ||
| + | |||
| + | except | ||
| + | |||
| + | filter | ||
| + | |||
| + | first | ||
| + | |||
| + | firstWhere | ||
| + | |||
| + | flatMap | ||
| + | |||
| + | flatten | ||
| + | |||
| + | flip | ||
| + | |||
| + | forget | ||
| + | |||
| + | |||
| + | forPage | ||
| + | |||
| + | get | ||
| + | |||
| + | groupBy | ||
| + | |||
| + | has | ||
| + | |||
| + | implode | ||
| + | |||
| + | intersect | ||
| + | |||
| + | intersectByKeys | ||
| + | |||
| + | isEmpty | ||
| + | |||
| + | isNotEmpty | ||
| + | |||
| + | join | ||
| + | |||
| + | keyBy | ||
| + | |||
| + | keys | ||
| + | |||
| + | last | ||
| + | |||
| + | macro | ||
| + | |||
| + | make | ||
| + | |||
| + | map | ||
| + | |||
| + | |||
| + | mapInto | ||
| + | |||
| + | |||
| + | mapSpread | ||
| + | |||
| + | mapToGroups | ||
| + | |||
| + | mapWithKeys | ||
| + | |||
| + | |||
| + | max | ||
| + | |||
| + | median | ||
| + | |||
| + | merge | ||
| + | |||
| + | |||
| + | mergeRecursive | ||
| + | |||
| + | min | ||
| + | |||
| + | mode | ||
| + | |||
| + | nth | ||
| + | |||
| + | only | ||
| + | |||
| + | pad | ||
| + | |||
| + | partition | ||
| + | |||
| + | pipe | ||
| + | |||
| + | pipeInto | ||
| + | |||
| + | pluck | ||
| + | |||
| + | pop | ||
| + | |||
| + | prepend | ||
| + | |||
| + | pull | ||
| + | |||
| + | push | ||
| + | |||
| + | put | ||
| + | |||
| + | random | ||
| + | |||
| + | reduce | ||
| + | |||
| + | reject | ||
| + | |||
| + | replace | ||
| + | |||
| + | replaceRecursive | ||
| + | |||
| + | reverse | ||
| + | |||
| + | search | ||
| + | |||
| + | |||
| + | |||
| + | shift | ||
| + | |||
| + | shuffle | ||
| + | |||
| + | skip | ||
| + | |||
| + | skipUntil | ||
| + | |||
| + | skipWhile | ||
| + | |||
| + | slice | ||
| + | |||
| + | some | ||
| + | |||
| + | sort | ||
| + | |||
| + | sortBy | ||
| + | |||
| + | sortByDesc | ||
| + | |||
| + | sortDesc | ||
| + | |||
| + | sortKeys | ||
| + | |||
| + | sortKeysDesc | ||
| + | |||
| + | splice | ||
| + | |||
| + | split | ||
| + | |||
| + | splitIn | ||
| + | |||
| + | sum | ||
| + | |||
| + | take | ||
| + | |||
| + | |||
| + | takeUntil | ||
| + | |||
| + | takeWhile | ||
| + | |||
| + | tap | ||
| + | |||
| + | times | ||
| + | |||
| + | toArray | ||
| + | |||
| + | toJson | ||
| + | |||
| + | transform | ||
| + | |||
| + | |||
| + | union | ||
| + | |||
| + | unique | ||
| + | |||
| + | uniqueStrict | ||
| + | |||
| + | unless | ||
| + | |||
| + | unlessEmpty | ||
| + | |||
| + | |||
| + | unlessNotEmpty | ||
| + | |||
| + | unwrap | ||
| + | |||
| + | values | ||
| + | |||
| + | when | ||
| + | |||
| + | whenEmpty | ||
| + | |||
| + | whenNotEmpty | ||
| + | |||
| + | where | ||
| + | |||
| + | whereStrict | ||
| + | |||
| + | whereBetween | ||
| + | |||
| + | |||
| + | whereIn | ||
| + | |||
| + | |||
| + | whereInStrict | ||
| + | |||
| + | whereInstanceOf | ||
| + | |||
| + | whereNotBetween | ||
| + | |||
| + | whereNotIn | ||
| + | |||
| + | whereNotInStrict | ||
| + | |||
| + | whereNotNull | ||
| + | |||
| + | whereNull | ||
| + | |||
| + | wrap | ||
| + | |||
| + | zip | ||
| + | |||
| + | |||
| + | |||
collections.1608751004.txt.gz · Last modified: 2023/09/14 06:06 (external edit)