The blog

Laravel 5: Reporting Application Exceptions With report

Apr 14, 2018

The report function is used to report an exception to the application's exception handler. It invokes the report method of the application exception handler with the provided exception. To use it, simply call the report function and pass in the exception you want to report.
Laravel 5: Resolving Authentication Policies With policy

Apr 14, 2018

The policy helper function retrieves a policy instance for a given class. It can be called with either a string or an object instance. If no policies have been registered for the class, an exception will be thrown. To use custom policies, they need to be mapped to their associated model class, typically within the AuthServiceProvider file. The policy helper function internally calls the getPolicyFor method on the authentication gate instance.
Laravel 5: Resolving Concrete Implementations From the Service Container With resolve

Apr 14, 2018

The resolve helper function is used to resolve a class instance from the Service Container. This function can be used to resolve any dependency from the Service Container as long as its constructor parameter dependencies can be resolved. Unlike the app helper function, it does not allow parameters to be supplied to the Service Container when resolving the dependency. For example, the resolve function can be used to resolve Laravel's event dispatcher from the Service Container by calling resolve('events').
Laravel 5: Retrieving Environment Variables With env

Apr 14, 2018

The env function in PHP is used to retrieve the value of an environment variable. It allows you to specify a default value to be returned if the variable is not set. The function automatically converts boolean string representations and null representations into their corresponding PHP values.
Laravel 5: Throwing HTTP Exceptions With abort

Apr 14, 2018

Learn how to use the abort function in Symfony to throw and handle HTTP exceptions. When called, the abort function will throw an instance of Symfony\Component\HttpKernel\Exception\HttpException with the provided code, message, and headers. If the code is 404, it will throw Symfony\Component\HttpKernel\Exception\NotFoundHttpException using only the user-supplied message. Check out the example to see how to use the abort function to handle unauthorized access with a 401 error code.
Laravel 5: Triggering Events With event

Apr 14, 2018

The event helper function allows you to conveniently dispatch events and their listeners. You can dispatch events by their name or by instantiating a new instance of the event class. The function also supports object-based events without the need for an event dispatcher dependency. The function returns an array of responses from the listeners.
Laravel 5: Adding a New Element to the Beginning of an Array With prepend

Apr 11, 2018

Learn how to use the prepend helper method in Laravel to add a new item to the beginning of an array. Control the key of the new item by specifying an optional parameter. The prepend method does not modify the original array and returns a modified copy.
Laravel 5: Adding Elements to the Array with add

Apr 11, 2018

The add helper method allows you to add a key-value pair to an array if the key doesn't already exist. To use the add method, pass in the array, key, and value as arguments, and the method will return the updated array. Alternatively, you can use the global array_add function, which is a shortcut for calling Arr::add directly.
Laravel 5: Adding or Setting New Array Element Values With set

Apr 11, 2018

The set method in Laravel is used to set values within an array, and it is the opposite of the forget method. This function modifies the original array. It uses dot notation for the key and can also be used to change the entire array by passing null as the key. There is also a global array_set helper function available as a shortcut to calling Arr::set.
Laravel 5: Array Helper Functions

Apr 11, 2018

Learn about Laravel's helper functions for manipulating array data structures. These functions offer additional features beyond PHP's built-in array functions and are located within the "Illuminate\Support\Arr" static class. Most of these functions treat arrays as immutable, meaning changes return a copy of the original array while leaving the original array unchanged. Laravel's array functions also support "dot" notation for accessing items in an array, similar to JavaScript's dot notation for accessing object properties. Explore various Laravel array helper functions like adding elements, splitting arrays, collapsing multi-dimensional arrays, representing multi-dimensional arrays in dot notation, excluding and filtering array elements, reducing arrays, finding occurrences, checking if an array contains an element, adding or setting array element values, removing elements, and retrieving array values.
Laravel 5: Checking if an Array Contains an Element With has

Apr 11, 2018

Learn how to use the has helper method in Laravel to check if a specific key exists in a nested array using dot notation. Discover how this method provides an easier and more readable alternative to using PHP's isset function. Additionally, find out how to use the global array_has helper function as a shortcut to calling the Arr::has method.
Laravel 5: Checking if an Array is an Associative Array With isAssoc

Apr 11, 2018

The isAssoc helper method checks if a given array is an associative array. An array is considered associative if it does not have sequential numeric keys starting from zero. The method returns true if the array is associative, and false otherwise. The provided example demonstrates how the method determines if arrays are associative or not.
Laravel 5: Collapsing a Multi-Dimensional Array to a Single Level With collapse

Apr 11, 2018

The collapse helper method in Laravel's Illuminate\Support\Arr class allows you to collapse a nested array into a single-level array. The method accepts an array as its parameter and returns a new array with the contents of all the nested arrays. The method can work with arrays that contain any data type. Keep in mind that the collapse method is not recursive, so it won't collapse arrays within nested arrays. However, the method can also be used on collections, including nested collections. Additionally, Laravel provides a global array_collapse helper function which is a shortcut to calling the Arr::collapse method.
Laravel 5: Conditionally Retrieving Array Values With where

Apr 11, 2018

The where helper method in Laravel is used to filter an array based on a callback function. It iterates over each element in the array and executes the callback on each key-value pair. If the callback returns a value that evaluates to true, the key-value pair is kept in the filtered array. This method can be used to compare both array values and key-value pairs. Additionally, Laravel provides a global array_where helper function, which is a shortcut to calling Arr::where.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.