Laravel Collections Introducution and examples - PART 1

1 minute read · 72 views · 8 likes

Note: This article was published over a year ago. Information within may have changed since then. While efforts are made to keep content current, please verify critical details before making decisions based on this information.

Programming Languages and Frameworks are a way of expressing the data we have. They all are worthless if we do not have any data. The idea of laravel eloquent is to provide a powerful ORM, where we can do many magic functions with less codes to write.

In this series of articles, we'll explore the power and versatility of Laravel Collections. I have divided this series into the following articles, from time to time, I will update the series accordingly:

Part 1:

  • all
  • average
  • avg
  • chunk
  • chunkWhile
  • collapse
  • collect
  • combine
  • concat
  • contains
  • containsOneItem
  • containsStrict
  • count
  • countBy
  • crossJoin

Part 2:

  • dd
  • diff
  • diffAssoc
  • diffAssocUsing
  • diffKeys
  • doesntContain
  • dot
  • dump
  • duplicates
  • duplicatesStrict
  • each
  • eachSpread
  • ensure
  • every
  • except

Part 3:

  • filter
  • first
  • firstOrFail
  • firstWhere
  • flatMap
  • flatten
  • flip
  • forget
  • forPage
  • get
  • groupBy
  • has
  • hasAny
  • implode
  • intersect

Part 4:

  • intersectAssoc
  • intersectByKeys
  • isEmpty
  • isNotEmpty
  • join
  • keyBy
  • keys
  • last
  • lazy
  • macro
  • make
  • map
  • mapInto
  • mapSpread
  • mapToGroups

Part 5:

  • mapWithKeys
  • max
  • median
  • merge
  • mergeRecursive
  • min
  • mode
  • nth
  • only
  • pad
  • partition
  • percentage
  • pipe
  • pipeInto
  • pipeThrough

Part 6:

  • pluck
  • pop
  • prepend
  • pull
  • push
  • put
  • random
  • range
  • reduce
  • reduceSpread
  • reject
  • replace
  • replaceRecursive
  • reverse
  • search

Part 7:

  • shift
  • shuffle
  • skip
  • skipUntil
  • skipWhile
  • slice
  • sliding
  • sole
  • some
  • sort
  • sortBy
  • sortByDesc
  • sortDesc
  • sortKeys
  • sortKeysDesc

Part 8:

  • sortKeysUsing
  • splice
  • split
  • splitIn
  • sum
  • take
  • takeUntil
  • takeWhile
  • tap
  • times
  • toArray
  • toJson
  • transform
  • undot
  • union

Part 9:

  • unique
  • uniqueStrict
  • unless
  • unlessEmpty
  • unlessNotEmpty
  • unwrap
  • value
  • values
  • when
  • whenEmpty
  • whenNotEmpty
  • where
  • whereStrict
  • whereBetween
  • whereIn

Part 10:

  • whereInStrict
  • whereInstanceOf
  • whereNotBetween
  • whereNotIn
  • whereNotInStrict
  • whereNotNull
  • whereNull
  • wrap
  • zip