User Tools

Site Tools


collections

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
collections [2020/12/23 19:18] chifekcollections [2023/09/14 06:06] (current) – external edit 127.0.0.1
Line 39: Line 39:
 </code> </code>
 Typically, you should declare collection macros in the boot method of a service provider. 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:
 +
 +<code>
 +use Illuminate\Support\Collection;
 +use Illuminate\Support\Facades\Lang;
 +use Illuminate\Support\Str;
 +
 +Collection::macro('toLocale', function ($locale) {
 +    return $this->map(function ($value) use ($locale) {
 +        return Lang::get($value, $locale);
 +    });
 +});
 +
 +$collection = collect(['first', 'second']);
 +
 +$translated = $collection->toLocale('es');
 +</code>
 +
 +**Available Methods**
 +
 +For the majority of the remaining collection documentation, we'll discuss each method available on the Collection class. Remember, all of these methods may be chained to fluently manipulate the underlying array. Furthermore, almost every method returns a new Collection instance, allowing you to preserve the original copy of the collection when necessary:
 +
 +
 +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.1608751083.txt.gz · Last modified: 2023/09/14 06:06 (external edit)