Search

In Laravel 5

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.
Laravel 5: Creating Combinations of Elements With crossJoin

Apr 11, 2018

The crossJoin method in Laravel's Illuminate\Support\Arr class allows you to combine input arrays, resulting in an array containing all possible combinations of the input values. Through an example, let's say we want to create a deck of cards. We can use crossJoin to combine arrays representing card suits and card values, resulting in a deck of 52 cards. We can further customize the deck by using array_map to transform the deck into a new array containing values in the format of of . Another example is using crossJoin to generate test payloads for browser testing, allowing you to create test cases for input element names and XSS payloads.
Laravel 5: Determining if an Array Contains an Element With exists

Apr 11, 2018

Learn how to use the exists helper method in Laravel. This method allows you to check if a key or index exists in an array. It is similar to PHP's array_key_exists function. The method requires two parameters, the array and the key. You can use any value that returns true from the Arr::accessible helper method as the array value. Check out the example use cases to see it in action.
Laravel 5: Determining if an Object is Array Accessible With accessible

Apr 11, 2018

The accessible helper method determines if a value is array accessible by checking if it is an array or an instance of ArrayAccess. The method returns true if the value is array accessible, and false otherwise.
Laravel 5: Ensuring a Value is an Array With wrap

Apr 11, 2018

Learn about the wrap method in Laravel's Arr class, which allows you to easily convert a value to an array. See an example of how to use the wrap method to convert a non-array value to an array. Also, discover a global helper function called array_wrap that performs the same task as Arr::wrap.

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.