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.
Laravel 5 String Helpers: Getting the Singular Form of a String Value Dec 6, 2017
The singular method is used to return the singular form of a given word. It is the opposite of the plural method. The method follows similar internal mechanisms as the plural method. There are certain words and word endings that are not affected by this method. The str_singular function is a global helper function that can be used instead of Str::singular.
Laravel 5 String Helpers: Parse Callback Dec 6, 2017
Learn how to use the parseCallback method in Laravel to break a string into a class name and method name. This method is helpful when working with class names and method names that are separated by the @ symbol. You can also specify a default method name to be used if there is no @ symbol or if nothing is on the right side of it. The function returns an array with the class name as the first element and the method name as the second element.
Laravel 5 String Helpers: Pluralization and Strings Dec 6, 2017
The plural helper method in Laravel returns a plural version of a given value. It applies general rules to strings to handle common cases, but also has special cases that it does not attempt to pluralize. Starting with version 5, Laravel uses the doctrine/inflector package for word inflections. The plural method takes a value and an optional count. It can be used to pluralize words in different scenarios, such as displaying message counts to users. There are special cases and word patterns that are not pluralized by the plural method, and Laravel also provides a global str_plural helper function as a shortcut to calling Str::plural.
Laravel 5 String Helpers: Replacing the First Occurrence of a Value Dec 6, 2017
The replaceFirst helper method allows you to replace the first occurrence of a given string with another string in a target string. All three parameters are required and must be strings. An example use of this method is replacing the protocol in a URL. Additionally, there is a global str_replace_first helper function available for convenience.