Laravel Companion: Second Edition
$14.99
Minimum price
$19.99
Suggested price

Laravel Companion: Second Edition

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!

About the Author

Johnathon Koster
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

Table of Contents

  •  
    • Who is This Book For?
    • Symbols Used In This Book
    • What Was Used to Write This Book?
  • String Helper Functions
    • Immutable Strings
    • Returning Part of a String After Another String With after
      • Signature
      • Example Use
    • Returning Part of a String Before Another String With before
      • Signature
      • Example Use
    • Converting Strings to ASCII Encoding With ascii
      • Signature
      • Example Use
    • Formatting Strings With StudlyCapsFormatting With studly
      • Signature
      • Example Use
      • Global studly_case Helper Function
    • Formatting Strings With camelCasing With camel
      • Signature
      • Example Use
      • Global camel_case Helper Function
    • Formatting Strings With snake_casing With snake
      • Signature
      • Example Use
      • Global snake_case Helper Function
    • Formatting Strings With kebab-casing With kebab
      • Signature
      • Example Use
      • Global kebab_case Helper Function
    • Formatting Strings With Title Casing Using title
      • Signature
      • Example Use
      • Global title_case Helper Function
    • Generating URL Strings With slug
      • Signature
      • Example Use
      • Global str_slug Helper Function
    • Checking if a String Contains Another String With contains
      • Signature
      • Example Use
      • Global str_contains Helper Function
    • Checking if a String Ends With Another String With endsWith
      • Signature
      • Example Use
      • Global ends_with Helper Function
    • Checking if a String Starts With Another String With startsWith
      • Signature
      • Example Use
      • Global starts_with Helper Function
    • Ensuring a String Always Ends With a Particular Value With finish
      • Signature
      • Example Use
      • Global str_finish Helper Function
    • Ensuring a String Always Starts With a Certain Value With start
      • Signature
      • Example Use
      • Global str_start Helper Function
    • String Pattern Matching With is
      • Signature
      • Example Use
      • Global str_is Helper Function
    • Calculating String Length With length
      • Signature
      • Example Use
    • Limiting String Length With End Caps (…) With limit
      • Signature
      • Example Use
      • Global str_limit Helper Function
    • Limiting the Number of Words In a String With an End Cap (…) With words
      • Signature
      • Example Use
    • Creating Lowercase Variants of Strings With lower
      • Signature
      • Example Use
    • Generating the Upper-Cased Variants of Strings With upper
      • Signature
      • Example Use
    • Pluralizing Strings With plural
      • Signature
      • Example Use
      • plural Special Cases
      • Global str_plural Helper Function
    • Converting Pluralized Strings to Their Singular Counterpart With singular
      • Signature
      • Example Use
      • singular Special Cases
      • Global str_singular Helper Function
    • Generating Random String Sequences With random
      • Signature
      • Example Use
      • Global str_random Helper Function
    • Parsing Class and Method Names With parseCallback
      • Signature
      • Example Use
    • Replacing the First Occurrence of a String With replaceFirst
      • Signature
      • Example Use
      • Global str_replace_first Helper Function
    • Replacing the Last Occurrence of a String With replaceLast
      • Signature
      • Example Use
      • Global str_replace_last Helper Function
    • Getting Portions of a String With substr
      • Signature
      • Example Use
    • Uppercasing the First Letter of a String With ucfirst
      • Signature
      • Example Use
    • String Translation With __
      • Signature
      • Example Use
      • Supplying a Locale
      • Example Within Blade Templates
    • String Translation With trans
      • Signature
      • Example Use
      • Supplying a Locale
      • Resolving Translator Instance
      • Retrieving Translations Without a Fallback Locale
    • String Translation With trans_choice
      • Signature
      • Example Use
    • HTML Encoding With e
      • Signature
      • Example Use
      • Working With Htmlable Values
  • String Translation: The File Loader
    • PHP Based Language Files
    • JSON Based Language Files
  • The FileLoader Public API
    • Loading Language Files With load
      • Signature
      • Example Use
      • Loading JSON Language Files Using load
      • Special Parameters
    • Adding Translation Namespaces With addNamespace
      • Signature
      • Example Use
    • Adding JSON Language Files With addJsonPath
      • Signature
      • Example Use
    • Retrieving Namespace Information With namespaces
      • Signature
      • Example Use
  • String Translation: The Translator Public API
    • Retrieving Translation Line Text With get
      • Signature
      • Example Use
      • Retrieving Translation Lines
      • Providing Replacements for Translation Lines
      • Specifying a Locale
      • Suppressing Fallback Local Translation Lines
    • Retrieving Translation Lines from JSON Language Files With getFromJson
      • Signature
      • Example Use
    • Translating Strings With trans
      • Signature
      • Example Use
    • Determining if a Translation Line Exists With has
      • Signature
      • Example Use
    • Determining if a Locale Has a Translation Line With hasForLocale
      • Signature
      • Example Use
    • Translating Strings Based on a Number of Items With choice
      • Signature
      • Example Use
      • Determining the Count of Items in a Collection
      • Specifying the Locale
      • The transChoice Method
    • Loading Translation Text Lines With load
      • Signature
      • Loader load vs. Translator load
    • Retrieving the Translation Loader With getLoader
      • Signature
    • Adding Translation Namespaces With addNamespace
      • Signature
    • Adding JSON Translation Files With addJsonPath
      • Signature
    • Adding Arbitrary Translation Lines With addLines
      • Signature
      • Example Use
    • Parsing Translation Keys With parseKey
      • Signature
      • Example Use
    • Working with Translator Message Selectors
      • Retrieving a Message Selector Instance With getSelector
      • Setting the Message Selector Instance With setSelector
    • Working with Translator Locales
      • Setting the Application Locale With setLocale
      • Getting the Application Locale With getLocale
      • Getting the Application Locale With locale
      • Setting the Fallback Locale With setFallback
      • Getting the Fallback Locale With getFallback
  • String Translation: Pluralization Syntax
    • Handling Specific Numbers
      • Examples of Specific Numbers
    • Ranges
      • Creating a Range Between Two Numbers
      • Creating Negative Ranges
  • Array Helper Functions
    • Immutable Arrays
    • Array Dot Notation
    • Adding Elements to the Arrays With add
      • Signature
      • Example Use
      • Global array_add Helper Function
    • Splitting an Array Into It’s Keys and Values With divide
      • Signature
      • Example Use
      • Global array_divide Helper Function
    • Collapsing a Multi-Dimensional Array to a Single Level With collapse
      • Signature
      • Example Use
      • Collapsing Collections
      • Global array_collapse Helper Function
    • Representing Multi-Dimensional Arrays in Dot Notation With dot
      • Signature
      • Example Use
      • Global array_dot Helper Function
    • Excluding Items From an Array With except
      • Signature
      • Example Use
      • Global array_except Helper Function
    • Filtering Array Elements With only
      • Signature
      • Example Use
      • Global array_only Helper Function
    • Reducing a Multi-Dimensional Array to a Single Dimension Losing Keys With flatten
      • Signature Use
      • Example Use
      • Global array_flatten Helper Function
    • Finding the First Occurrence of an Element Matching a Condition With first
      • Signature
      • Example Use
      • Optional $callback Parameter
      • Global array_first Helper Function
    • Finding the Last Occurrence of an Element Matching a Condition With last
      • Signature
      • Example Use
      • Optional $callback Parameter
      • Global array_last Helper Function
    • Checking if an Array Contains an Element With has
      • Signature
      • Example Use
      • Global array_has Helper Function
    • Adding or Setting New Array Element Values With set
      • Signature
      • Example Use
      • Using set to change the entire array
      • Replacing the $array With a New Array
      • Replacing the $array With a Completely Different Type
      • Global array_set Helper Function
    • Removing Elements From an Array With forget
      • Signature
      • Example Use
      • Global array_forget Helper Function
    • Retrieving Elements from an Array With get
      • Signature
      • Example Use
      • Global array_get Helper Function
    • Retrieving, and Removing an Element From an Array With pull
      • Signature
      • Example Use
      • Global array_pull Helper Function
    • Retrieving Nested Array Values With pluck
      • Signature
      • Example Use
      • Returning an array with a key/value pair
      • Working With Nested Arrays or Objects
      • Global array_pluck Helper Function
    • Conditionally Retrieving Array Values With where
      • Signature
      • Example Use
      • Global array_where Helper Function
    • Sorting Arrays With sort
      • Signature
      • Example Use
      • Global array_sort Helper Function
    • Checking if an Array is an Associative Array With isAssoc
      • Signature
      • Example Use
    • Determining if an Object is Array Accessible With accessible
      • Signature
      • Example Use
    • Determining if an Array Contains an Element With exists
      • Signature
      • Example Use
    • Adding a New Element to the Beginning of an Array With prepend
      • Signature
      • Example Use
      • Global array_prepend Helper Function
    • Creating Combinations of Elements With crossJoin
      • Signature
      • Example Use
    • Ensuring a Value is an Array With wrap
      • Signature
      • Example Use
      • Global array_wrap Helper Function
    • Randomizing Element Order With shuffle
      • Signature
      • Example Use
    • Retrieving Random Elements from an Array With random
      • Signature
      • Example Use
      • Global array_random Helper Function
    • Getting the First Element of an Array With head
      • Signature
      • Example Use
    • Getting the Last Element of an Array With last
      • Signature
      • Example Use
  • Application and User Flow Helper Functions
    • Accessing the Service Container With app
      • Signature
      • Example Use
    • Resolving Concrete Implementations From the Service Container With resolve
      • Signature
      • Example Use
    • Accessing the Authentication Manager With auth
      • Signature
      • Example Use
    • Resolving Authentication Policies With policy
      • Signature
      • Example Use
    • Generating Paths Relative to the Application Root With app_path
      • Signature
      • Example Use
    • Generating Paths Relative to the Application Installation Directory With base_path
      • Signature
      • Example Use
    • Generating Paths Relative to the Configuration Directory With config_path
      • Signature
      • Example Use
    • Generating Paths Relative to the Database Directory With database_path
      • Signature
      • Example Use
    • Generating Paths Relative to the Public Directory With public_path
      • Signature
      • Example Use
    • Generating Paths Relative to the Storage Directory With storage_path
      • Signature
      • Example Use
    • Generating Paths Relative to the Resource Directory With resource_path
      • Signature
      • Example Use
    • Accessing the Cache System With cache
      • Signature
      • Example Use
    • Managing HTTP Cookies With cookie
      • Signature
      • Example Use
    • Accessing and Manipulating Session Data With session
      • Signature
      • Returning an Instance of “\Illuminate\Session\SessionManager”
      • Setting a Session Value
      • Retrieving a Session Value
    • Throwing HTTP Exceptions With abort
      • Signature
      • Example Use
    • Conditionally Throwing HTTP Exceptions With abort_if
      • Signature
      • Example Use
    • Conditionally Throwing HTTP Exceptions With abort_unless
      • Signature
      • Example Use
    • Conditionally Throwing Exceptions With throw_if
      • Signature
      • Example Use
    • Conditionally Throwing Exceptions With throw_unless
      • Signature
      • Example Use
    • Recover From Possible Exceptions With rescue
      • Signature
      • Example Use
    • Attempt an Error-Prone Operation a Number of Times With retry
      • Signature
      • Example Use
    • Comparing abort, abort_if and abort_unless
    • Performing HTTP Redirects With redirect
      • Signature
      • Accessing the Redirector Instance Using redirect
      • Redirecting to a Given Path
      • Redirecting to Secure URLs
      • Redirecting to Custom URLs
      • Changing the HTTP Status Code
      • Supplying Additional Headers
    • Redirecting Users to the Previous Page With back
      • Signature
      • Example Use
      • Returning a Redirect Response Using the Redirect Facade
      • Returning a Redirect Response Using the response Helper Function
      • Returning a redirect response using the back helper function:
      • Changing the HTTP Status Code
      • Supplying Additional Headers
    • Accessing and Sending HTTP Responses With response
      • Signature
      • Example Use
      • Changing the HTTP Status Code
      • Supplying Additional Headers
    • Accessing HTTP Request Details With request
      • Signature
      • Example Use
    • Rendering Views to Strings and Returning View Responses With view
      • Signature
      • Example Use
      • Rendering a View to a String
    • Accessing Session Input Data With old
      • Signature
      • Example Use
    • Triggering Events With event
      • Signature
      • Example Use
    • Notifying Server Side Clients of Events With broadcast
      • Signature
      • Example Use
    • Dispatching Queued Jobs With dispatch
      • Signature
      • Example Use
    • Dispatching Queued Jobs Immediately With dispatch_now
      • Signature
      • Example Use
    • Creating Eloquent Models for Testing With factory
      • Signature
      • Example Use
    • Generating an HTML Field for HTTP Verbs With method_field
      • Signature
      • Example Use
    • Accessing Validation Features With validator
      • Signature
      • Example Use
  • Configuration, Environment, Security and Logging Helper Functions
    • Hashing Strings With bcrypt
      • Signature
      • Example Use
      • Available Options
    • Encrypting Strings With encrypt
      • Signature
      • Example Use
    • Decrypting Strings With decrypt
      • Signature
      • Example Use
    • Generating CSRF Hidden HTML Fields With csrf_field
      • Signature
      • Example Use
    • Generating CSRF Session Tokens With csrf_token
      • Signature
      • Example Use
    • Accessing and Manipulating Configuration Values With config
      • Signature
      • Example Use
      • Setting Configuration Values
      • Retrieving Configuration Values
    • Retrieving Environment Variables With env
      • Signature
      • Example Use
    • Accessing the Logging Features With logger
      • Signature
      • Example Use
    • Logging Informative Messages With info
      • Signature
      • Example Use
    • Reporting Application Exceptions With report
      • Signature
      • Example Use
  • URL Generation Helper Functions
    • Generating URLs to Controller Actions With action
      • Signature
      • Example Use
      • Relative URLs
    • Generating URLs to Assets With asset
      • Signature
      • Example Use
    • Generating Secure URLs to Assets With secure_asset
      • Signature
      • Example Use
      • Notes on asset and secure_asset
    • Generating URLs With url
      • Signature
      • Example Use
      • Generating Secure URLs
    • Generating HTTPS URLs With secure_url
      • Signature
      • Example Use
    • Generating URLs to Named Routes With route
      • Signature
      • Example Use
    • Generating Public URLs to Elixir Compiled Assets With elixir
      • Signature
      • Example Use
    • Generating Public URLs to Mix Compiled Assets With mix
      • Signature
      • Example Use
      • Changing the Manifest Directory
  • Miscellaneous Helper Functions
    • Displaying Variable Data and Stopping Script Execution for Debugging With dd
      • Signature
      • Example Use
    • Getting Array or Object Values With data_get
      • Signature
      • Example Use
    • Setting Array or Object Values With data_set
      • Signature
      • Example Use
      • Using data_set With Objects
    • Setting Data on Objects Without Overwriting Existing Data With data_fill
      • Signature
      • Example Use
    • Retrieving Object Values With object_get
      • Signature
      • Example Use
    • Checking if a Variable Holds a Value With filled
      • Signature
      • Example Use
    • Determining if a Variable Holds a Value With blank
      • Signature
      • Example Use
    • Provide Default Values for Object Properties With optional
      • Signature
      • Example Use
    • Determining Which Traits a Class Uses With trait_uses_recursive
      • Signature
      • Example Use
    • Finding What Traits a Class Uses With class_uses_recursive
      • Signature
      • Example Use
    • Retrieving the Default Value of a Given Variable With value
      • Signature
      • Example Use
    • Returning In-line Access to a Variable With with
      • Signature
      • Example Use
    • Conditionally Transforming/Changing Values With transform
      • Signature
      • Example Use
    • Getting the Current Date and Time With now
      • Signature
      • Example Use
    • Get the Current Date With today
      • Signature
      • Example Use
    • Checking if the Script is Executing on a Windows Machine With windows_os
      • Signature
      • Example Use
    • Execute a Callback on a Given Value While Chaining the Original Value With tap
      • Signature
      • Example Use
      • Using tap to Proxy Method Calls
    • Getting the Class Name for an Object Instance With class_basename
      • Signature
      • Example Use
  • Collection Basics
    • Creating a New Collection Instance
  • Collections: The Public API
    • Retrieving Collection Elements With all
      • Signature
      • Example Use
    • Convert a Collection to a Native PHP Array With toArray
      • Signature
      • Example Use
    • Splitting a Collection Into Smaller Pieces With chunk
      • Signature
      • Example Use
    • Converting a Multi-Dimensional Collection Into a Single Dimension With collapse
      • Signature
      • Example Use
    • Determining If a Collection Contains an Element With contains
      • Signature
      • Example Use
      • Considerations of the contains Method
      • Using contains With Higher Order Messages
    • Determining if a Collection Contains an Element Using Strict Comparison With containsStrict
      • Signature
      • Example Use
    • Getting the Number of Elements in a Collection With count
      • Signature
      • Example Use
    • Determine Which Collection Elements are Not Present in the Provided Collections With diff
      • Signature
      • Example Use
    • Returning Collection Elements That Are Not Present in the Specified Collections With diffAssoc
      • Signature
      • Example Use
    • Retrieving Collection Elements Whose Keys Are Not Present in the Provided Keys With diffKeys
      • Signature
      • Example Use
    • Executing a Function On All Collection Elements With each
      • Signature
      • Example Use
      • Using each With Higher Order Messages
    • Filtering Collection Elements With filter
      • Signature
      • Example Use
      • Using filter With Higher Order Messages
    • Getting the First Collection Element With first
      • Signature
      • Example Use
      • Using first With Higher Order Messages
    • Reducing a Multi-Dimensional Collection to a Single Dimension Losing Keys With flatten
      • Signature
      • Example Use
    • Swapping Element Keys and Values With flip
      • Signature
      • Example Use
    • Paginating Collections With forPage
      • Signature
      • Example Use
      • Using chunk to Achieve Similar Results
    • Removing Collection Elements With forget
      • Signature
      • Example Use
    • Retrieving Collection Elements With get
      • Signature
      • Example Use
    • Grouping Collection Elements With groupBy
      • Signature
      • Example Use
      • Preserving Keys With groupBy
    • Determining If a Collection Has An Element With has
      • Signature
      • Example Use
    • Combining Collection Elements Into a String With implode
      • Signature
      • Example Use
    • Filtering Collections Based On Value Presence With intersect
      • Signature
      • Example Use
    • Checking If a Collection Contains Items With isEmpty
      • Signature
      • Example Use
    • Converting a Collection Into Something JSON Serializeable With jsonSerialize
      • Signature
      • Example Use
    • Retrieving the Collection Element’s Keys With keys
      • Signature
      • Example Use
    • Getting the Last Collection Element With last
      • Signature
      • Example Use
    • Transforming Collection Elements With map
      • Signature
      • Example Use
      • Using map with Higher Order Messages
    • Mapping Collection Elements and Reducing to a Single Dimension With flatMap
      • Signature
      • Example Use
      • Using flatMap With Higher Order Messages
    • Retrieving the Maximum Value of a Collection With max
      • Signature
      • Example Use
    • Merging Multiple Collection Values With merge
      • Signature
      • Example Use
    • Calculating the Minimum Value of a Collection With min
      • Signature
      • Example Use
    • Retrieving Collection Element Values With pluck
      • Signature
      • Example Use
    • Retrieving and Removing the Last Collection Element With pop
      • Signature
      • Example Use
    • Adding an Element to the Beginning of a Collection With prepend
      • Signature
      • Example Use
    • Retrieving and Removing an Element From a Collection With pull
      • Signature
      • Example Use
    • Adding an Element to the End of a Collection With push
      • Signature
      • Example Use
    • Adding New Elements to a Collection With put
      • Signature
      • Example Use
    • Retrieving Random Collection Elements With random
      • Signature
      • Example Use
    • Reducing a Collection to One Element With reduce
      • Signature
      • Example Use
    • Conditionally Removing Elements From a Collection With reject
      • Signature
      • Example Use
      • Using reject With Higher Order Messages
    • Reversing the Order of Collection Elements With reverse
      • Signature
      • Example Use
    • Finding an Element Key Conditionally With search
      • Signature
      • Example Use
    • Removing the First Element of a Collection With shift
      • Signature
      • Example Use
    • Randomizing Element Order With shuffle
      • Signature
      • Example Use
    • Retrieving a Portion of a Collection With slice
      • Signature
      • Example Use
    • Sorting a Collection With sort
      • Signature
      • Example Use
      • Custom Sorting Comparison Function
    • Sorting a Collection Based on a Key Value With sortBy
      • Signature
      • Example Use
      • sortBy Options
      • Sorting Flag Comparison Table
      • The SORT_NUMERIC Flag
      • The SORT_STRING Flag
      • SORT_STRING and SORT_FLAG_CASE Flags for Case Insensitivity
      • The SORT_LOCALE_STRING Flag
      • The SORT_NATURAL Flag
      • The SORT_NATURAL and SORT_FLAG_CASE Flags for Case Insensitivity
      • Using sortBy With Higher Order Messages
    • Sort a Collection in Descending Order With sortByDesc
      • Signature
      • Example Use
      • Using sortByDesc With Higher Order Messages
    • Removing a Portion of a Collection With splice
      • Signature
      • Example Use
    • Calculating the Average Value of a Collection With avg
      • Signature
      • Example Use
      • Averaging Nested Collections
      • Using avg With Higher Order Messages
    • Calculating the Average Value of a Collection With average
      • Signature
      • Example Use
      • Using average With Higher Order Messages
    • Calculating the Sum of a Collection With sum
      • Signature
      • Example Use
      • Using sum With Higher Order Messages
    • Retrieving a Specified Number of Items From a Collection With take
      • Signature
      • Example Use
    • Converting a Collection’s Contents to JSON With toJson
      • Signature
      • Example Use
      • toJson and Deeply Nested Data Structures
    • Converting a Collection to JSON With PHP’s Magic __toString Method
    • Modifying Collection Elements With transform
      • Signature
      • Example Use
    • Retrieving the Distinct Values of a Collection With unique
      • Signature
      • Example Use
    • Retrieving Only the Values of a Collection’s Elements With values
      • Signature
      • Example Use
    • Filtering Collection Elements With where
      • Signature
      • Example Use
    • Pair the Values of a Collection With the Values of Other Collections With zip
      • Signature
      • Example Use
    • Combining the Keys of a Collection With the Values of Another Collection With combine
      • Signature
      • Example Use
    • Testing All Collection Values With every
      • Signature
      • Example Use
      • Using every With Higher Order Messages
    • Excluding Collection Elements With except
      • Signature
      • Example Use
    • Retrieving a Subset Of a Collections Elements With only
      • Signature
      • Example Use
    • Transforming Collection Element Keys With keyBy
      • Signature
      • Example Use
    • Filtering a Collection Based On Key Presence With whereIn
      • Signature
      • Example Use
    • Creating Combination of Elements With crossJoin
      • Signature
      • Example Use
    • Dumping the Collection Contents and Stopping Script Execution for Debugging With dd
      • Signature
      • Example Use
    • Dumping the Collection Contents and Continuing Script Execution for Debugging With dump
      • Signature
      • Example Use
    • Executing a Function on Collection Elements With eachSpread
      • Signature
      • Example Use
    • Filtering Collections Based on Key Presence With intersectByKeys
      • Signature
      • Example Use
    • Checking If a Collection Contains Items With isNotEmpty
      • Signature
      • Example Use
    • Convert Collection Elements Into Object Instances With mapInto
      • Signature
      • Example Use
    • Executing a Function on Collection Elements and Values With mapSpread
      • Signature
      • Example Use
      • Replicating the Behavior of the LINQ Zip Operator
    • Reducing a Collection Into a Collection of Key/Array-Value Pairs With mapToDictionary
      • Signature
      • Example Use
    • Reducing a Collection Into a Collection of Key/Collection-Value Pairs With mapToGroups
      • Signature
      • Example Use
    • Reducing a Collection With User-Defined Keys With mapWithKeys
      • Signature
      • Example Use
    • Retrieving Collection Elements At a Specific Interval With nth
      • Signature
      • Example Use
    • Ensuring a Collection Always Contains a Specified Number of Elements With pad
      • Signature
      • Example Use
    • Filtering Collections With (Without Losing Filtered Rejections) partition
      • Signature
      • Example Use
      • Using partition With Higher Order Messages
    • Executing a Function on a Collection and Returning the Function Results With pipe
      • Signature
      • Example Use
    • Breaking a Collection Into a Specified Number of Groups With split
      • Signature
      • Example Use
    • Adding Values to a Collection With union
      • Signature
      • Example Use
    • Retrieving the Distinct Values of a Collection Using Strict Comparison Operators With uniqueStrict
      • Signature
      • Example Use
    • Conditionally Executing a Callback On a Collection’s Elements With unless
      • Signature
      • Example Use
    • Conditionally Executing a Callback On a Collection’s Elements With when
      • Signature
      • Example Use
    • Filtering a Collection Based On Key Presence Using Strict Comparison Operators With whereInStrict
      • Signature
      • Example Use
    • Filtering a Collection Based On Key Presence Using Strict Comparison Operators With whereNotInStrict
      • Signature
      • Example Use
    • Filtering a Collection Based On Key Presence With whereNotIn
      • Signature
      • Example Use
      • Performing Strict Comparisons
    • Filtering Collection Elements Using Strict Comparison Operators With whereStrict
      • Signature
      • Example Use
    • Calculating the Median Value of a Collection With median
      • Signature
      • Example Use
    • Determining the Most Common Value in a Collection With mode
      • Signature
      • Example Use
    • Combining the Values of Multiple Traversable Sources With concat
      • Signature
      • Example Use
    • Execute a Callback on the Collection Instance While Returning the Original Collection Instance With tap
      • Signature
      • Example Use
    • Creating a Copy of a Collection With toBase
      • Signature
      • Example Use
  • Collections: The Static API
    • Creating a New Collection Instance From Arrays Using make
      • Signature
      • Example Use
    • Ensure a Value Is a Collection With wrap
      • Signature
      • Example Use
    • Returning the Items of a Collection With unwrap
      • Signature
      • Example Use
    • Creating a Collection By Invoking a Callback a Given Number of Times With times
      • Signature
      • Example Use
    • Adding Methods to the Higher Order Message List With proxy
      • Signature
      • Example Use
  • Message Bags
    • The MessageProvider Interface
  • The MessageBag Public API
    • Adding Messages to the Message Bag With add
      • Signature
      • Example Use
      • Notes on Keys
    • Retrieving Messages With a Provided Format With all
      • Signature
      • Example Use
    • Determining if There are Any Messages With any
      • Signature
      • Example Use
    • Checking if There Are Any Messages With isNotEmpty
      • Signature
      • Example Use
    • Retrieving the Number of Messages With count
      • Signature
      • Example Use
    • Retrieving the First Message With first
      • Signature
      • Example Use
    • Getting Specific Messages With get
      • Signature
      • Example Use
    • Getting the Current Message Format With getFormat
      • Signature
      • Example Use
    • Returning the Message Bag Instance With getMessageBag
      • Signature
      • Example Use
    • Getting an Array of Messages With getMessages
      • Signature
      • Example Use
    • Checking if Messages Exist for a Specific Input Key With has
      • Signature
    • Checking if There Are Any Messages With isEmpty
      • Signature
      • Example Use
    • Converting the Message Bag to Something JSON Serializeable With jsonSerialize
      • Signature
      • Example Use
    • Getting all of the Message Keys With keys
      • Signature
      • Example Use
    • Merging Additional Messages With merge
      • Signature
      • Example Use
    • Setting the Message Format With setFormat
      • Signature
    • Converting the Message Bag to an Array With toArray
      • Signature
      • Example Use
    • Converting the Message Bag to JSON With toJson
      • Signature
      • Example Use
      • toJson and Deeply Nested Data Structures
    • __toString
      • Signature
      • Example Use
  • View Error Bags
  • The ViewErrorBag Public API
    • Getting the Number of Error Messages With count
      • Signature
      • Example Use
    • Determining if There Are Any Error Messages With any
      • Signature
      • Example Use
    • Getting the Message Bag Instance With getBag
      • Signature
      • Example Use
    • Getting all Message Bag Instances With getBags
      • Signature
      • Example Use
    • Determining if a Message Bag Exists With hasBag
      • Signature
      • Example Use
    • Add a New Message Bag Instance to the View Error Bag With put
      • Signature
      • Example Use
      • Resetting MessageBag Messages
  • Dynamic Data Containers and the Fluent Data Type
  • Fluent Public API
    • Retrieving Values With get
      • Signature
      • Example Use
    • Fluent and Closures
    • Getting Key/Value Data Associations With getAttributes
      • Signature
      • Example Use
    • Converting the Data Object to an Array With toArray
      • Signature
      • Example Use
    • Converting the Data Object to Something JSON Serializeable With jsonSerialize
      • Signature
      • Example Use
    • Converting the Object to JSON With toJson
      • Signature
      • Example Use
      • toJson and Deeply Nested Data Structures
  • Augmenting Framework Behavior With Macros
    • Default Classes That Support Macros
    • Creating a Callback Function Macro
    • Creating Class Based Macros with Mixins
    • Framework Classes with Dynamic Methods Available
    • Notes on Eloquent Builder
  • Macroable Public API
    • Defining a Callback Function Macro With macro
      • Signature
      • Example Use
    • Injecting Class-Based Macros With mixin
      • Signature
      • Example Use
    • Determining if a Class Has a Macro Defined With hasMacro
      • Signature
      • Example Use
    • Macroable Implementation of PHP’s Magic __call Method
      • Signature
    • Macroable Implementation of PHP’s Magic __callStatic Method
      • Signature
    • Important Notes On __call and __callStatic
  • Facades
    • Facade Aliases and Importing Facades
    • Using Facades
    • Creating Facades
      • Creating a Facade Alias
    • Facade Class Reference
      • Notes on Blade
      • Notes on Schema
      • Additional Cookie Methods
      • Additional Input Methods
      • Additional Schema Methods
      • Additional Notification Methods
      • Additional Queue Methods
      • Additional Storage Methods
    • Resolving the Class Behind a Facade
  • Appendix A: Available Hash Functions
  • Appendix B: HTTP Status Codes
  • Appendix C: Language Specific Replacements
    • Bulgarian
    • German
  • Notes

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...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

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

In fact, authors have earnedover $13 millionwriting, 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