The blog

Laravel 5: Retrieving, and Removing an Element From an Array With pull

Apr 11, 2018

The pull helper method in Laravel is used to retrieve and remove a value from an array. It can be used with a default value if the desired key does not exist. This method directly modifies the original array. An example use case is removing a specific day from an array of weekdays in PHP. The pull method can be accessed through the Arr class in Laravel, or through the global array_pull helper function.
Laravel 5: Retrieving Elements from an Array With get

Apr 11, 2018

The get helper method allows developers to quickly retrieve items from an array using dot notation, without having to use PHP's array syntax. The method also supports a default value, which will be returned if the specified key is not found in the array. An alternative to using the get method is to use PHP's array access syntax and the isset function, but the dot notation code is shorter and easier to read. Additionally, there is a global array_get helper function available as a shortcut to calling Arr::get.
Laravel 5: Retrieving Nested Array Values With pluck

Apr 11, 2018

The pluck helper method is used to retrieve specific values from an array. It can be used on arrays of objects or arrays of arrays. You can also use dot notation to retrieve values from nested arrays or objects. Additionally, there is a global array_pluck function available as a shortcut to Arr::pluck.
Laravel 5: Retrieving Random Elements from an Array With random

Apr 11, 2018

The random method in PHP's Illuminate\Support\Arr class allows you to retrieve random items from an input array. You can specify the number of random items to be returned, and if not specified, it will return one random item. Be cautious when specifying a number greater than the array's length, as it will throw an exception. Note that the random method is not suitable for cryptographic purposes since it relies on PHP's array_rand function. There is also a global helper function, array_random, that serves as a shortcut to calling the Arr::random method.
Laravel 5: Sorting Arrays With sort

Apr 11, 2018

The sort helper method allows you to sort an array based on some condition returned by a callback function. It iterates over the values in the array and uses the value returned by the callback to determine the sort order. You can also use the array_sort function as a shortcut to calling Arr::sort. Keep in mind that the array_sort function internally creates a new Collection object and should not be used in a certain way to avoid unnecessary object creation.
Laravel 5: Splitting an Array Into It's Keys and Values with divide

Apr 11, 2018

The divide helper method in Laravel separates an array into two new arrays: one containing all the keys and the other containing all the values. This can be useful when you need to work with the keys and values separately. You can use the divide method by calling Arr::divide and passing in the array you want to divide. Additionally, Laravel provides a global array_divide helper function that is a shortcut to calling Arr::divide.
Laravel 5: String Translation Public API

Feb 20, 2018

The "Illuminate\Translation\Translator" class in Laravel is responsible for handling translation services. It can be used to retrieve translation lines, process replacements, and specify a locale. The get method retrieves the translation line for a given key, with the option to pass in replacements. The getFromJson method is similar, but allows retrieval from JSON-based language files.
Laravel 5: Encoding HTML With the "e" Helper Function

Feb 19, 2018

The e function is a convenient PHP wrapper for the htmlentities function, allowing you to sanitize user input when displaying it on a webpage. It encodes HTML special characters, preventing malicious users from injecting JavaScript or other code into your website. The function also handles Htmlable values differently and does not encode the HTML characters within their toHtml() return value. By using the e function, you can ensure that your webpage is safe and protected from cross-site scripting (XSS) attacks.
Laravel 5: String Pluralization Syntax

Feb 19, 2018

This section explores the concept of handling specific numbers in pluralization translation. It explains how to associate a given message number with a specific number of items and provides examples of handling specific numbers. It also introduces the concept of ranges in translation files and demonstrates how to create a range between two numbers and handle negative ranges.
Laravel 5: The Translator's File Loader

Feb 19, 2018

The FileLoader class is responsible for loading translation files from the file system. By default, language files are loaded from the /resources/lang/ directory. Each sub-directory within this directory corresponds to a locale and contains PHP files or JSON files with key/value translations. The JSON files use dot notation to retrieve nested translation strings.
Laravel 5 Translation Using the Double Underscore (__) Helper Function

Feb 19, 2018

Learn how to use the __ helper function in Laravel to retrieve lines of text from language files. You can retrieve text from translation files using key-based translation files or literal translation files. Replacement keys can be used to replace placeholders in the translation string. The __ method has the signature __($key, $replace = [], $locale = null). You can also supply a locale to translate the text into a specific language. Examples of using the __ function both in code and within Blade templates are provided.
Laravel 5.5: Translating Strings With the `trans` Helper Function

Feb 19, 2018

The trans method in Laravel is used to retrieve translation lines from language files. It works similarly to the get method but does not allow changing fallback locale behavior. The method always uses the fallback locale for translation lines that are not defined in other locales. You can also use the trans method with replacement attributes and specify a specific locale for translation.
Laravel 5.5: Translating Strings with the "trans_choice" Helper Function

Feb 19, 2018

Learn how to use the trans_choice helper function to translate text based on the number of items in a collection. This function accepts an array of replacements to dynamically build out the translated string and uses placeholders to match the replacements. The $number parameter is required, even if you are translating a collection with only one item. See examples of the trans_choice method in action to understand how it works.
Laravel 5 String Helpers: Generating Random Strings

Dec 6, 2017

The random helper method in Laravel generates a random string of the specified length. It uses the OpenSSL function openssl_random_pseudo_bytes and requires the OpenSSL extension to be installed. If called without the OpenSSL extension, a RuntimeException will be thrown. There is also a global str_random helper function available as a shortcut to calling Str::random.

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.