Leanpub Header

Skip to main content

Laravel Companion: Second Edition

A progressive discovery of the Laravel helper features, functions, classes, utilities, Collections, and more!

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
681
Pages
About

About

About the Book

The Laravel Companion Second Edition takes you through the helper features, function, classes, utilities and much, much more of the Laravel Framework.

Updated and expanded for Laravel 5.5, you are sure to learn something about the features that are easily overlooked or are easily forgotten. As we progress together through the book, we will export all of the string helper functions, array helpers, Collections, and much, much more through hundreds of practical code examples (including interacting with The Open Movie Database API and gathering weather forecasts).

The content for this book will be adapted for a web format and uploaded for free at https://stillat.com; purchasing this book helps to ensure the continued development of new content; thank you!

Price

Pick Your Price...

Minimum price

Free!

$19.99

You pay

$19.99

Author earns

$15.99
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 0)

0
The author will earn $0.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Johnathon Koster

Hello, internet!

My name is John, and I have over fifteen years of professional software development. I've worked on a wide range of projects over the years, from simple websites and critical government reporting applications all the way to high-performance telematics solutions.

During my downtime, I enjoy working on open-source projects, writing posts on my blog, and contributing to the Laravel and Statamic ecosystems.

Some of the recent open-source projects I've worked on include:

  • blade-parser-typescript - a Laravel Blade parser, formatter, reflection library, and linter, written in TypeScript
  • Antlers Toolbox - a Visual Studio Code extension providing syntax highlighting, code auto-complete, intelligent refactoring, and project-aware assistance for Statamic developers
  • Antlers Runtime - an advanced PHP templating engine for the Statamic CMS platform
  • Proteus - a Laravel package that makes it simple to read, write, and modify Laravel configuration files from your application code
  • Primitives - a PHP library that safely parses input strings into native PHP types (string, bool, arrays, etc.) and can optionally be configured with a sandbox for method evaluation
Leanpub Podcast

Episode 242

An Interview with Johnathon Koster

Contents

Table of Contents

Who is This Book For?

  1. Symbols Used In This Book
  2. What Was Used to Write This Book?

String Helper Functions

  1. Immutable Strings
  2. Returning Part of a String After Another String With after
  3. Signature
  4. Example Use
  5. Returning Part of a String Before Another String With before
  6. Signature
  7. Example Use
  8. Converting Strings to ASCII Encoding With ascii
  9. Signature
  10. Example Use
  11. Formatting Strings With StudlyCapsFormatting With studly
  12. Signature
  13. Example Use
  14. Pascal Case
  15. Global studly_case Helper Function
  16. Formatting Strings With camelCasing With camel
  17. Signature
  18. Example Use
  19. Global camel_case Helper Function
  20. Formatting Strings With snake_casing With snake
  21. Signature
  22. Example Use
  23. Global snake_case Helper Function
  24. Formatting Strings With kebab-casing With kebab
  25. Signature
  26. Example Use
  27. Global kebab_case Helper Function
  28. Formatting Strings With Title Casing Using title
  29. Signature
  30. Example Use
  31. Global title_case Helper Function
  32. Generating URL Strings With slug
  33. Signature
  34. Example Use
  35. Global str_slug Helper Function
  36. Checking if a String Contains Another String With contains
  37. Signature
  38. Example Use
  39. Global str_contains Helper Function
  40. Checking if a String Ends With Another String With endsWith
  41. Signature
  42. Example Use
  43. Global ends_with Helper Function
  44. Checking if a String Starts With Another String With startsWith
  45. Signature
  46. Example Use
  47. Global starts_with Helper Function
  48. Ensuring a String Always Ends With a Particular Value With finish
  49. Signature
  50. Example Use
  51. Global str_finish Helper Function
  52. Ensuring a String Always Starts With a Certain Value With start
  53. Signature
  54. Example Use
  55. Global str_start Helper Function
  56. String Pattern Matching With is
  57. Signature
  58. Example Use
  59. Global str_is Helper Function
  60. Calculating String Length With length
  61. Signature
  62. Example Use
  63. str_repeat($input, $multiplier)
  64. Limiting String Length With End Caps (…) With limit
  65. Signature
  66. Example Use
  67. Global str_limit Helper Function
  68. Limiting the Number of Words In a String With an End Cap (…) With words
  69. Signature
  70. Example Use
  71. Creating Lowercase Variants of Strings With lower
  72. Signature
  73. Example Use
  74. Generating the Upper-Cased Variants of Strings With upper
  75. Signature
  76. Example Use
  77. Pluralizing Strings With plural
  78. Signature
  79. Example Use
  80. plural Special Cases
  81. Global str_plural Helper Function
  82. Converting Pluralized Strings to Their Singular Counterpart With singular
  83. Signature
  84. Example Use
  85. singular Special Cases
  86. Global str_singular Helper Function
  87. Generating Random String Sequences With random
  88. Signature
  89. Example Use
  90. Global str_random Helper Function
  91. Parsing Class and Method Names With parseCallback
  92. Signature
  93. Example Use
  94. Replacing the First Occurrence of a String With replaceFirst
  95. Signature
  96. Example Use
  97. Global str_replace_first Helper Function
  98. Replacing the Last Occurrence of a String With replaceLast
  99. Signature
  100. Example Use
  101. Global str_replace_last Helper Function
  102. Getting Portions of a String With substr
  103. substr Encoding
  104. Signature
  105. Example Use
  106. Uppercasing the First Letter of a String With ucfirst
  107. Signature
  108. Example Use
  109. String Translation With __
  110. Signature
  111. Example Use
  112. Supplying a Locale
  113. Example Within Blade Templates
  114. String Translation With trans
  115. Signature
  116. Example Use
  117. Supplying a Locale
  118. Resolving Translator Instance
  119. Retrieving Translations Without a Fallback Locale
  120. String Translation With trans_choice
  121. Signature
  122. Example Use
  123. HTML Encoding With e
  124. Signature
  125. Example Use
  126. Working With Htmlable Values

String Translation: The File Loader

  1. PHP Based Language Files
  2. JSON Based Language Files

The FileLoader Public API

  1. Loading Language Files With load
  2. Signature
  3. Example Use
  4. Loading JSON Language Files Using load
  5. Special Parameters
  6. Adding Translation Namespaces With addNamespace
  7. Signature
  8. Example Use
  9. Adding JSON Language Files With addJsonPath
  10. Signature
  11. Example Use
  12. Retrieving Namespace Information With namespaces
  13. Signature
  14. Example Use

String Translation: The Translator Public API

  1. Retrieving Translation Line Text With get
  2. Signature
  3. Example Use
  4. Retrieving Translation Lines
  5. Providing Replacements for Translation Lines
  6. Specifying a Locale
  7. Suppressing Fallback Local Translation Lines
  8. Retrieving Translation Lines from JSON Language Files With getFromJson
  9. Signature
  10. Example Use
  11. Translating Strings With trans
  12. Signature
  13. Example Use
  14. Determining if a Translation Line Exists With has
  15. Signature
  16. Example Use
  17. Determining if a Locale Has a Translation Line With hasForLocale
  18. Signature
  19. Example Use
  20. Translating Strings Based on a Number of Items With choice
  21. Signature
  22. Example Use
  23. Determining the Count of Items in a Collection
  24. Specifying the Locale
  25. The transChoice Method
  26. Loading Translation Text Lines With load
  27. Signature
  28. Loader load vs. Translator load
  29. Retrieving the Translation Loader With getLoader
  30. Signature
  31. Adding Translation Namespaces With addNamespace
  32. Signature
  33. Adding JSON Translation Files With addJsonPath
  34. Signature
  35. Adding Arbitrary Translation Lines With addLines
  36. Signature
  37. Example Use
  38. Parsing Translation Keys With parseKey
  39. Signature
  40. Example Use
  41. Working with Translator Message Selectors
  42. Retrieving a Message Selector Instance With getSelector
  43. Setting the Message Selector Instance With setSelector
  44. Working with Translator Locales
  45. Setting the Application Locale With setLocale
  46. Getting the Application Locale With getLocale
  47. Getting the Application Locale With locale
  48. Setting the Fallback Locale With setFallback
  49. Getting the Fallback Locale With getFallback

String Translation: Pluralization Syntax

  1. Handling Specific Numbers
  2. Examples of Specific Numbers
  3. Ranges
  4. Creating a Range Between Two Numbers
  5. Creating Negative Ranges

Array Helper Functions

  1. Immutable Arrays
  2. Array Dot Notation
  3. Adding Elements to the Arrays With add
  4. Signature
  5. Example Use
  6. Global array_add Helper Function
  7. Splitting an Array Into It’s Keys and Values With divide
  8. Signature
  9. Example Use
  10. Global array_divide Helper Function
  11. Collapsing a Multi-Dimensional Array to a Single Level With collapse
  12. Signature
  13. Example Use
  14. Collapsing Collections
  15. Global array_collapse Helper Function
  16. Representing Multi-Dimensional Arrays in Dot Notation With dot
  17. Signature
  18. Example Use
  19. Global array_dot Helper Function
  20. Excluding Items From an Array With except
  21. Signature
  22. Example Use
  23. Global array_except Helper Function
  24. Filtering Array Elements With only
  25. Signature
  26. Example Use
  27. Global array_only Helper Function
  28. Reducing a Multi-Dimensional Array to a Single Dimension Losing Keys With flatten
  29. Signature Use
  30. Example Use
  31. Global array_flatten Helper Function
  32. Finding the First Occurrence of an Element Matching a Condition With first
  33. Signature
  34. Example Use
  35. Optional $callback Parameter
  36. Global array_first Helper Function
  37. Finding the Last Occurrence of an Element Matching a Condition With last
  38. Signature
  39. Example Use
  40. Optional $callback Parameter
  41. Global array_last Helper Function
  42. Checking if an Array Contains an Element With has
  43. Signature
  44. Example Use
  45. Global array_has Helper Function
  46. Adding or Setting New Array Element Values With set
  47. Mutable Function
  48. Signature
  49. Example Use
  50. Using set to change the entire array
  51. Replacing the $array With a New Array
  52. Replacing the $array With a Completely Different Type
  53. Global array_set Helper Function
  54. Removing Elements From an Array With forget
  55. Signature
  56. Example Use
  57. Global array_forget Helper Function
  58. Retrieving Elements from an Array With get
  59. Signature
  60. Example Use
  61. Global array_get Helper Function
  62. Retrieving, and Removing an Element From an Array With pull
  63. Signature
  64. Example Use
  65. Global array_pull Helper Function
  66. Retrieving Nested Array Values With pluck
  67. Signature
  68. Example Use
  69. Returning an array with a key/value pair
  70. Working With Nested Arrays or Objects
  71. Global array_pluck Helper Function
  72. Conditionally Retrieving Array Values With where
  73. Signature
  74. Example Use
  75. Anonymous Functions and Variable Scope
  76. Global array_where Helper Function
  77. Sorting Arrays With sort
  78. Signature
  79. Example Use
  80. Array Sort Considerations
  81. Global array_sort Helper Function
  82. Checking if an Array is an Associative Array With isAssoc
  83. Signature
  84. Example Use
  85. Determining if an Object is Array Accessible With accessible
  86. Signature
  87. Example Use
  88. Determining if an Array Contains an Element With exists
  89. Signature
  90. Example Use
  91. Adding a New Element to the Beginning of an Array With prepend
  92. Signature
  93. Example Use
  94. Global array_prepend Helper Function
  95. Creating Combinations of Elements With crossJoin
  96. Signature
  97. Example Use
  98. Ensuring a Value is an Array With wrap
  99. Signature
  100. Example Use
  101. Global array_wrap Helper Function
  102. Randomizing Element Order With shuffle
  103. Signature
  104. Example Use
  105. Retrieving Random Elements from an Array With random
  106. Signature
  107. Example Use
  108. Global array_random Helper Function
  109. Getting the First Element of an Array With head
  110. Signature
  111. Example Use
  112. Getting the Last Element of an Array With last
  113. Signature
  114. Example Use

Application and User Flow Helper Functions

  1. Accessing the Service Container With app
  2. Signature
  3. Example Use
  4. Resolving Concrete Implementations From the Service Container With resolve
  5. Signature
  6. Example Use
  7. Accessing the Authentication Manager With auth
  8. Signature
  9. Example Use
  10. Resolving Authentication Policies With policy
  11. Signature
  12. Example Use
  13. Generating Paths Relative to the Application Root With app_path
  14. Signature
  15. Example Use
  16. Generating Paths Relative to the Application Installation Directory With base_path
  17. Signature
  18. Example Use
  19. Generating Paths Relative to the Configuration Directory With config_path
  20. Signature
  21. Example Use
  22. Generating Paths Relative to the Database Directory With database_path
  23. Signature
  24. Example Use
  25. Generating Paths Relative to the Public Directory With public_path
  26. Signature
  27. Example Use
  28. Generating Paths Relative to the Storage Directory With storage_path
  29. Signature
  30. Example Use
  31. Generating Paths Relative to the Resource Directory With resource_path
  32. Signature
  33. Example Use
  34. Accessing the Cache System With cache
  35. Signature
  36. Example Use
  37. Managing HTTP Cookies With cookie
  38. Signature
  39. Example Use
  40. Accessing and Manipulating Session Data With session
  41. Signature
  42. Returning an Instance of “\Illuminate\Session\SessionManager”
  43. Setting a Session Value
  44. Retrieving a Session Value
  45. Throwing HTTP Exceptions With abort
  46. Signature
  47. Example Use
  48. Conditionally Throwing HTTP Exceptions With abort_if
  49. Signature
  50. Example Use
  51. Conditionally Throwing HTTP Exceptions With abort_unless
  52. Signature
  53. Example Use
  54. Conditionally Throwing Exceptions With throw_if
  55. Signature
  56. Example Use
  57. Conditionally Throwing Exceptions With throw_unless
  58. Signature
  59. Example Use
  60. Recover From Possible Exceptions With rescue
  61. Signature
  62. Example Use
  63. Attempt an Error-Prone Operation a Number of Times With retry
  64. Signature
  65. Example Use
  66. Comparing abort, abort_if and abort_unless
  67. Performing HTTP Redirects With redirect
  68. Signature
  69. Accessing the Redirector Instance Using redirect
  70. Redirecting to a Given Path
  71. Redirecting to Secure URLs
  72. Redirecting to Custom URLs
  73. Changing the HTTP Status Code
  74. Supplying Additional Headers
  75. Redirecting Users to the Previous Page With back
  76. Signature
  77. Example Use
  78. Returning a Redirect Response Using the Redirect Facade
  79. Returning a Redirect Response Using the response Helper Function
  80. Returning a redirect response using the back helper function:
  81. Changing the HTTP Status Code
  82. Supplying Additional Headers
  83. Accessing and Sending HTTP Responses With response
  84. Signature
  85. Example Use
  86. Changing the HTTP Status Code
  87. Supplying Additional Headers
  88. Accessing HTTP Request Details With request
  89. Signature
  90. Example Use
  91. Rendering Views to Strings and Returning View Responses With view
  92. Signature
  93. Example Use
  94. Rendering a View to a String
  95. Accessing Session Input Data With old
  96. Signature
  97. Example Use
  98. Triggering Events With event
  99. Signature
  100. Example Use
  101. Notifying Server Side Clients of Events With broadcast
  102. Signature
  103. Example Use
  104. Dispatching Queued Jobs With dispatch
  105. Signature
  106. Example Use
  107. Dispatching Queued Jobs Immediately With dispatch_now
  108. Signature
  109. Example Use
  110. Creating Eloquent Models for Testing With factory
  111. Signature
  112. Example Use
  113. Generating an HTML Field for HTTP Verbs With method_field
  114. Signature
  115. Example Use
  116. Accessing Validation Features With validator
  117. Signature
  118. Example Use

Configuration, Environment, Security and Logging Helper Functions

  1. Hashing Strings With bcrypt
  2. Signature
  3. Example Use
  4. Available Options
  5. Encrypting Strings With encrypt
  6. Signature
  7. Example Use
  8. Decrypting Strings With decrypt
  9. Signature
  10. Example Use
  11. Generating CSRF Hidden HTML Fields With csrf_field
  12. Signature
  13. Example Use
  14. Generating CSRF Session Tokens With csrf_token
  15. Signature
  16. Example Use
  17. Accessing and Manipulating Configuration Values With config
  18. Signature
  19. Example Use
  20. Setting Configuration Values
  21. Retrieving Configuration Values
  22. Retrieving Environment Variables With env
  23. Signature
  24. Example Use
  25. Accessing the Logging Features With logger
  26. Signature
  27. Example Use
  28. Logging Informative Messages With info
  29. Signature
  30. Example Use
  31. Reporting Application Exceptions With report
  32. Signature
  33. Example Use

URL Generation Helper Functions

  1. Generating URLs to Controller Actions With action
  2. Signature
  3. Example Use
  4. Relative URLs
  5. Generating URLs to Assets With asset
  6. Signature
  7. Example Use
  8. Generating Secure URLs to Assets With secure_asset
  9. Signature
  10. Example Use
  11. Notes on asset and secure_asset
  12. Generating URLs With url
  13. Signature
  14. Example Use
  15. Generating Secure URLs
  16. Generating HTTPS URLs With secure_url
  17. Signature
  18. Example Use
  19. Generating URLs to Named Routes With route
  20. Signature
  21. Example Use
  22. Generating Public URLs to Elixir Compiled Assets With elixir
  23. Signature
  24. Example Use
  25. Generating Public URLs to Mix Compiled Assets With mix
  26. Signature
  27. Example Use
  28. Changing the Manifest Directory

Miscellaneous Helper Functions

  1. Displaying Variable Data and Stopping Script Execution for Debugging With dd
  2. Signature
  3. Example Use
  4. Getting Array or Object Values With data_get
  5. Signature
  6. Example Use
  7. Setting Array or Object Values With data_set
  8. Signature
  9. Example Use
  10. Using data_set With Objects
  11. Setting Data on Objects Without Overwriting Existing Data With data_fill
  12. Signature
  13. Example Use
  14. Retrieving Object Values With object_get
  15. Signature
  16. Example Use
  17. Checking if a Variable Holds a Value With filled
  18. Signature
  19. Example Use
  20. Determining if a Variable Holds a Value With blank
  21. Signature
  22. Example Use
  23. Provide Default Values for Object Properties With optional
  24. Signature
  25. Example Use
  26. Determining Which Traits a Class Uses With trait_uses_recursive
  27. Signature
  28. Example Use
  29. Finding What Traits a Class Uses With class_uses_recursive
  30. Signature
  31. Example Use
  32. Retrieving the Default Value of a Given Variable With value
  33. Signature
  34. Example Use
  35. Returning In-line Access to a Variable With with
  36. Signature
  37. Example Use
  38. Alternative to the with Function
  39. Conditionally Transforming/Changing Values With transform
  40. Signature
  41. Example Use
  42. Getting the Current Date and Time With now
  43. Signature
  44. Example Use
  45. Get the Current Date With today
  46. Signature
  47. Example Use
  48. Checking if the Script is Executing on a Windows Machine With windows_os
  49. Signature
  50. Example Use
  51. Execute a Callback on a Given Value While Chaining the Original Value With tap
  52. Signature
  53. Example Use
  54. Tap Function Closure Arguments
  55. Using tap to Proxy Method Calls
  56. Getting the Class Name for an Object Instance With class_basename
  57. Signature
  58. Example Use

Collection Basics

  1. Creating a New Collection Instance

Collections: The Public API

  1. Retrieving Collection Elements With all
  2. Signature
  3. Example Use
  4. Convert a Collection to a Native PHP Array With toArray
  5. Signature
  6. Example Use
  7. Splitting a Collection Into Smaller Pieces With chunk
  8. Signature
  9. Example Use
  10. Converting a Multi-Dimensional Collection Into a Single Dimension With collapse
  11. Signature
  12. Example Use
  13. Determining If a Collection Contains an Element With contains
  14. Signature
  15. Example Use
  16. Considerations of the contains Method
  17. Using contains With Higher Order Messages
  18. Determining if a Collection Contains an Element Using Strict Comparison With containsStrict
  19. Signature
  20. Example Use
  21. Getting the Number of Elements in a Collection With count
  22. Signature
  23. Example Use
  24. Determine Which Collection Elements are Not Present in the Provided Collections With diff
  25. Signature
  26. Example Use
  27. Returning Collection Elements That Are Not Present in the Specified Collections With diffAssoc
  28. Signature
  29. Example Use
  30. Retrieving Collection Elements Whose Keys Are Not Present in the Provided Keys With diffKeys
  31. Signature
  32. Example Use
  33. Executing a Function On All Collection Elements With each
  34. Signature
  35. Example Use
  36. Using each With Higher Order Messages
  37. Filtering Collection Elements With filter
  38. Signature
  39. Example Use
  40. Using filter With Higher Order Messages
  41. Getting the First Collection Element With first
  42. Signature
  43. Example Use
  44. Using first With Higher Order Messages
  45. Reducing a Multi-Dimensional Collection to a Single Dimension Losing Keys With flatten
  46. Signature
  47. Example Use
  48. Swapping Element Keys and Values With flip
  49. Signature
  50. Example Use
  51. Paginating Collections With forPage
  52. Signature
  53. Example Use
  54. Using chunk to Achieve Similar Results
  55. Removing Collection Elements With forget
  56. Signature
  57. Example Use
  58. Retrieving Collection Elements With get
  59. Signature
  60. Example Use
  61. Grouping Collection Elements With groupBy
  62. Signature
  63. Example Use
  64. Preserving Keys With groupBy
  65. Determining If a Collection Has An Element With has
  66. Signature
  67. Example Use
  68. Combining Collection Elements Into a String With implode
  69. Signature
  70. Example Use
  71. Filtering Collections Based On Value Presence With intersect
  72. Signature
  73. Example Use
  74. Checking If a Collection Contains Items With isEmpty
  75. Signature
  76. Example Use
  77. Converting a Collection Into Something JSON Serializeable With jsonSerialize
  78. Signature
  79. Example Use
  80. Retrieving the Collection Element’s Keys With keys
  81. Signature
  82. Example Use
  83. Getting the Last Collection Element With last
  84. Signature
  85. Example Use
  86. Transforming Collection Elements With map
  87. Signature
  88. Example Use
  89. Using map with Higher Order Messages
  90. Mapping Collection Elements and Reducing to a Single Dimension With flatMap
  91. Signature
  92. Example Use
  93. Using flatMap With Higher Order Messages
  94. Retrieving the Maximum Value of a Collection With max
  95. Signature
  96. Example Use
  97. Merging Multiple Collection Values With merge
  98. Signature
  99. Example Use
  100. Calculating the Minimum Value of a Collection With min
  101. Signature
  102. Example Use
  103. Retrieving Collection Element Values With pluck
  104. Signature
  105. Example Use
  106. Retrieving and Removing the Last Collection Element With pop
  107. Signature
  108. Example Use
  109. Adding an Element to the Beginning of a Collection With prepend
  110. Signature
  111. Example Use
  112. Retrieving and Removing an Element From a Collection With pull
  113. Signature
  114. Example Use
  115. Adding an Element to the End of a Collection With push
  116. Signature
  117. Example Use
  118. Adding New Elements to a Collection With put
  119. Signature
  120. Example Use
  121. Retrieving Random Collection Elements With random
  122. Signature
  123. Example Use
  124. Reducing a Collection to One Element With reduce
  125. Signature
  126. Example Use
  127. Conditionally Removing Elements From a Collection With reject
  128. Signature
  129. Example Use
  130. Using reject With Higher Order Messages
  131. Reversing the Order of Collection Elements With reverse
  132. Signature
  133. Example Use
  134. Finding an Element Key Conditionally With search
  135. Signature
  136. Example Use
  137. Removing the First Element of a Collection With shift
  138. Signature
  139. Example Use
  140. Randomizing Element Order With shuffle
  141. Signature
  142. Example Use
  143. Retrieving a Portion of a Collection With slice
  144. Signature
  145. Example Use
  146. Sorting a Collection With sort
  147. Signature
  148. Example Use
  149. Custom Sorting Comparison Function
  150. Sorting a Collection Based on a Key Value With sortBy
  151. Signature
  152. Example Use
  153. sortBy Options
  154. Sorting Flag Comparison Table
  155. The SORT_NUMERIC Flag
  156. The SORT_STRING Flag
  157. SORT_STRING and SORT_FLAG_CASE Flags for Case Insensitivity
  158. The SORT_LOCALE_STRING Flag
  159. The SORT_NATURAL Flag
  160. The SORT_NATURAL and SORT_FLAG_CASE Flags for Case Insensitivity
  161. Using sortBy With Higher Order Messages
  162. Sort a Collection in Descending Order With sortByDesc
  163. Signature
  164. Example Use
  165. Using sortByDesc With Higher Order Messages
  166. Removing a Portion of a Collection With splice
  167. Signature
  168. Example Use
  169. Calculating the Average Value of a Collection With avg
  170. Signature
  171. Example Use
  172. Averaging Nested Collections
  173. Using avg With Higher Order Messages
  174. Calculating the Average Value of a Collection With average
  175. Signature
  176. Example Use
  177. Using average With Higher Order Messages
  178. Calculating the Sum of a Collection With sum
  179. Signature
  180. Example Use
  181. Using sum With Higher Order Messages
  182. Retrieving a Specified Number of Items From a Collection With take
  183. Signature
  184. Example Use
  185. Converting a Collection’s Contents to JSON With toJson
  186. Signature
  187. Example Use
  188. toJson and Deeply Nested Data Structures
  189. Converting a Collection to JSON With PHP’s Magic __toString Method
  190. Modifying Collection Elements With transform
  191. Signature
  192. Example Use
  193. Retrieving the Distinct Values of a Collection With unique
  194. Signature
  195. Example Use
  196. Retrieving Only the Values of a Collection’s Elements With values
  197. Signature
  198. Example Use
  199. Filtering Collection Elements With where
  200. Signature
  201. Example Use
  202. Pair the Values of a Collection With the Values of Other Collections With zip
  203. Signature
  204. Example Use
  205. Combining the Keys of a Collection With the Values of Another Collection With combine
  206. Signature
  207. Example Use
  208. Testing All Collection Values With every
  209. Signature
  210. Example Use
  211. Using every With Higher Order Messages
  212. Excluding Collection Elements With except
  213. Signature
  214. Example Use
  215. Retrieving a Subset Of a Collections Elements With only
  216. Signature
  217. Example Use
  218. Transforming Collection Element Keys With keyBy
  219. Signature
  220. Example Use
  221. Filtering a Collection Based On Key Presence With whereIn
  222. Signature
  223. Example Use
  224. Creating Combination of Elements With crossJoin
  225. Signature
  226. Example Use
  227. Dumping the Collection Contents and Stopping Script Execution for Debugging With dd
  228. Signature
  229. Example Use
  230. Dumping the Collection Contents and Continuing Script Execution for Debugging With dump
  231. Signature
  232. Example Use
  233. Executing a Function on Collection Elements With eachSpread
  234. Signature
  235. Example Use
  236. Filtering Collections Based on Key Presence With intersectByKeys
  237. Signature
  238. Example Use
  239. Checking If a Collection Contains Items With isNotEmpty
  240. Signature
  241. Example Use
  242. Convert Collection Elements Into Object Instances With mapInto
  243. Signature
  244. Example Use
  245. Executing a Function on Collection Elements and Values With mapSpread
  246. Signature
  247. Example Use
  248. Replicating the Behavior of the LINQ Zip Operator
  249. Reducing a Collection Into a Collection of Key/Array-Value Pairs With mapToDictionary
  250. Signature
  251. Example Use
  252. Reducing a Collection Into a Collection of Key/Collection-Value Pairs With mapToGroups
  253. Signature
  254. Example Use
  255. Reducing a Collection With User-Defined Keys With mapWithKeys
  256. Signature
  257. Example Use
  258. Retrieving Collection Elements At a Specific Interval With nth
  259. Signature
  260. Example Use
  261. Ensuring a Collection Always Contains a Specified Number of Elements With pad
  262. Signature
  263. Example Use
  264. Filtering Collections With (Without Losing Filtered Rejections) partition
  265. Signature
  266. Example Use
  267. Using partition With Higher Order Messages
  268. Executing a Function on a Collection and Returning the Function Results With pipe
  269. Signature
  270. Example Use
  271. Breaking a Collection Into a Specified Number of Groups With split
  272. Signature
  273. Example Use
  274. Adding Values to a Collection With union
  275. Signature
  276. Example Use
  277. Retrieving the Distinct Values of a Collection Using Strict Comparison Operators With uniqueStrict
  278. Signature
  279. Example Use
  280. Conditionally Executing a Callback On a Collection’s Elements With unless
  281. Signature
  282. Example Use
  283. Conditionally Executing a Callback On a Collection’s Elements With when
  284. Signature
  285. Example Use
  286. Filtering a Collection Based On Key Presence Using Strict Comparison Operators With whereInStrict
  287. Signature
  288. Example Use
  289. Filtering a Collection Based On Key Presence Using Strict Comparison Operators With whereNotInStrict
  290. Signature
  291. Example Use
  292. Filtering a Collection Based On Key Presence With whereNotIn
  293. Signature
  294. Example Use
  295. Performing Strict Comparisons
  296. Filtering Collection Elements Using Strict Comparison Operators With whereStrict
  297. Signature
  298. Example Use
  299. Calculating the Median Value of a Collection With median
  300. Signature
  301. Example Use
  302. Determining the Most Common Value in a Collection With mode
  303. Signature
  304. Example Use
  305. Combining the Values of Multiple Traversable Sources With concat
  306. Signature
  307. Example Use
  308. Execute a Callback on the Collection Instance While Returning the Original Collection Instance With tap
  309. Signature
  310. Example Use
  311. Creating a Copy of a Collection With toBase
  312. Signature
  313. Example Use

Collections: The Static API

  1. Creating a New Collection Instance From Arrays Using make
  2. Signature
  3. Example Use
  4. Ensure a Value Is a Collection With wrap
  5. Signature
  6. Example Use
  7. Returning the Items of a Collection With unwrap
  8. Signature
  9. Example Use
  10. Creating a Collection By Invoking a Callback a Given Number of Times With times
  11. Signature
  12. Example Use
  13. Adding Methods to the Higher Order Message List With proxy
  14. Signature
  15. Example Use

Message Bags

  1. The MessageProvider Interface

The MessageBag Public API

  1. Adding Messages to the Message Bag With add
  2. Signature
  3. Example Use
  4. Notes on Keys
  5. Retrieving Messages With a Provided Format With all
  6. Signature
  7. Example Use
  8. Determining if There are Any Messages With any
  9. Signature
  10. Example Use
  11. Checking if There Are Any Messages With isNotEmpty
  12. Signature
  13. Example Use
  14. Retrieving the Number of Messages With count
  15. Signature
  16. Example Use
  17. Retrieving the First Message With first
  18. Signature
  19. Example Use
  20. Getting Specific Messages With get
  21. Signature
  22. Example Use
  23. Getting the Current Message Format With getFormat
  24. Signature
  25. Example Use
  26. Returning the Message Bag Instance With getMessageBag
  27. Signature
  28. Example Use
  29. Getting an Array of Messages With getMessages
  30. Signature
  31. Example Use
  32. Checking if Messages Exist for a Specific Input Key With has
  33. Signature
  34. Checking if There Are Any Messages With isEmpty
  35. Signature
  36. Example Use
  37. Converting the Message Bag to Something JSON Serializeable With jsonSerialize
  38. Signature
  39. Example Use
  40. Getting all of the Message Keys With keys
  41. Signature
  42. Example Use
  43. Merging Additional Messages With merge
  44. Signature
  45. Example Use
  46. Setting the Message Format With setFormat
  47. Signature
  48. Converting the Message Bag to an Array With toArray
  49. Signature
  50. Example Use
  51. Converting the Message Bag to JSON With toJson
  52. Signature
  53. Example Use
  54. toJson and Deeply Nested Data Structures
  55. __toString
  56. Signature
  57. Example Use

View Error Bags

The ViewErrorBag Public API

  1. Getting the Number of Error Messages With count
  2. Signature
  3. Example Use
  4. Determining if There Are Any Error Messages With any
  5. Signature
  6. Example Use
  7. Getting the Message Bag Instance With getBag
  8. Signature
  9. Example Use
  10. Getting all Message Bag Instances With getBags
  11. Signature
  12. Example Use
  13. Determining if a Message Bag Exists With hasBag
  14. Signature
  15. Example Use
  16. Add a New Message Bag Instance to the View Error Bag With put
  17. Signature
  18. Example Use
  19. Resetting MessageBag Messages

Dynamic Data Containers and the Fluent Data Type

Fluent Public API

  1. Retrieving Values With get
  2. Signature
  3. Example Use
  4. Fluent and Closures
  5. Getting Key/Value Data Associations With getAttributes
  6. Signature
  7. Example Use
  8. Converting the Data Object to an Array With toArray
  9. Signature
  10. Example Use
  11. Converting the Data Object to Something JSON Serializeable With jsonSerialize
  12. Signature
  13. Example Use
  14. Converting the Object to JSON With toJson
  15. Signature
  16. Example Use
  17. toJson and Deeply Nested Data Structures

Augmenting Framework Behavior With Macros

  1. Default Classes That Support Macros
  2. Creating a Callback Function Macro
  3. Creating Class Based Macros with Mixins
  4. Framework Classes with Dynamic Methods Available
  5. Notes on Eloquent Builder

Macroable Public API

  1. Defining a Callback Function Macro With macro
  2. Signature
  3. Example Use
  4. Injecting Class-Based Macros With mixin
  5. Signature
  6. Example Use
  7. Determining if a Class Has a Macro Defined With hasMacro
  8. Signature
  9. Example Use
  10. Macroable Implementation of PHP’s Magic __call Method
  11. Signature
  12. Macroable Implementation of PHP’s Magic __callStatic Method
  13. Signature
  14. Important Notes On __call and __callStatic

Facades

  1. Facade Aliases and Importing Facades
  2. Fully Qualified Names vs. Aliases
  3. Using Facades
  4. Creating Facades
  5. Creating a Facade Alias
  6. Facade Class Reference
  7. Notes on Blade
  8. Notes on Schema
  9. Additional Cookie Methods
  10. Additional Input Methods
  11. Additional Schema Methods
  12. Additional Notification Methods
  13. Additional Queue Methods
  14. Additional Storage Methods
  15. Resolving the Class Behind a Facade

Appendix A: Available Hash Functions

Appendix B: HTTP Status Codes

Appendix C: Language Specific Replacements

  1. Bulgarian
  2. German

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub