The blog

Laravel 5 View Error Bags: Determining if There Are Any Error Messages With any

Apr 21, 2018

The any method is a convenience shortcut to check if the error message bag contains any messages. It returns a boolean value indicating whether there are messages present or not. Instead of using count() > 0, you can simply use any() to perform certain actions when there are error messages.
Laravel 5 View Error Bags: Getting all Message Bag Instances With getBags

Apr 21, 2018

The getBags method retrieves all the MessageBag instances within the ViewErrorBag instance and returns an associative array. This allows you to retrieve and manipulate error messages in a convenient way. To use it, create a new ViewErrorBag instance, populate it with MessageBag instances, and then call the getBags method to retrieve the array of message bags.
Laravel 5 View Error Bags: Getting the Message Bag Instance With getBag

Apr 21, 2018

Learn how to use the getBag method to retrieve a MessageBag instance based on a provided key. If a MessageBag instance does not exist, a new instance will be returned instead. See code examples that demonstrate the usage and behavior of the getBag method, including accessing a MessageBag instance dynamically. Be aware of the behavior where the getBag method does not set the returned MessageBag instance.
Laravel 5 View Error Bags: Getting the Number of Error Messages With count

Apr 21, 2018

The count method in Laravel's MessageBag class returns the number of messages stored within the default instance of MessageBag. It is specifically handled by the ViewErrorBag instance, and needs to be declared within the ViewErrorBag class itself to satisfy PHP's Countable interface requirements. The example usage shows how the count method operates on the default MessageBag instance and how it can be affected by adding or changing the MessageBag instance.
Laravel 5: View Error Bags

Apr 21, 2018

Learn how to use the Illuminate\Support\ViewErrorBag class to communicate error messages with views and responses in Laravel. The ViewErrorBag acts as a container for instances of the Illuminate\Contracts\Support\MessageBag implementation. When a request contains errors, an instance of ViewErrorBag is shared with views, using the name errors. You can interact with the ViewErrorBag instance to access and display error messages in your views. The ViewErrorBag public API includes methods such as count, any, getBag, and more. Check out our blog post for more information and examples on working with Laravel view error bags.
Laravel 5: Checking if a Variable Holds a Value With filled

Apr 15, 2018

The filled helper function is used to determine if a provided value has a non-null or non-empty value. It checks if the value is not null, is a non-whitespace string with a length greater than 0, is a numeric value, is a boolean, is a Countable object with items, or if empty evaluates to false.
Laravel 5: Checking if the Script is Executing on a Windows Machine With windows_os

Apr 15, 2018

The windows_os helper function can be used to determine if the host server is running a Microsoft Windows® operating system. This function returns true if the server is running Windows®, and false if it is not. It provides a simpler and more readable way to check for the operating system compared to using PHP_OS and string manipulation.
Laravel 5: Conditionally Transforming/Changing Values With transform

Apr 15, 2018

The transform helper function is used to modify a provided value based on various conditions. If the value is not empty, it will be passed as an argument to a callback function and the results will be returned. If the value is empty, a default value will be returned instead. This can be particularly useful in situations where you want to handle empty values in a specific way, as shown in the example use case of retrieving a weather forecast.
Laravel 5: Determining if a Variable Holds a Value With blank

Apr 15, 2018

The blank function is a helpful PHP utility that allows you to check if a value is empty or null without having to check multiple types individually. It considers a value blank if it is null, an empty string, not numeric, not a boolean, an empty Countable object, or evaluated as true by the empty function. Use the blank function to simplify your value-checking logic in PHP.
Laravel 5: Determining Which Traits a Class Uses With trait_uses_recursive

Apr 15, 2018

The trait_uses_recursive function allows you to retrieve all traits used by a class, including traits used by other traits. It returns an array of the traits used. It can be used with both class names and class instances. The function only lists traits in the immediate class, not the base class.
Laravel 5: Displaying Variable Data and Stopping Script Execution for Debugging With dd

Apr 15, 2018

The dd function in PHP is a debug utility that displays useful information about objects or values provided as arguments. It also terminates the script and outputs the values in a structured format. The function is especially helpful for debugging in web development, as it adjusts its output based on whether the script is running in a console or a browser. An example usage demonstrates how the dd function can output an array and an object in a web browser.
Laravel 5: Execute a Callback on a Given Value While Chaining the Original Value With tap

Apr 15, 2018

The tap helper function in Laravel allows you to call a closure with a provided value and return the original value. This is useful for maintaining a reference to an object while calling methods on it, especially during method chaining. The helper function can be used to simplify code and eliminate the need for intermediate variables. It was added in Laravel 5.3 and can be easily integrated into older Laravel code bases.
Laravel 5: Finding What Traits a Class Uses With class_uses_recursive

Apr 15, 2018

The class_uses_recursive function is used to retrieve an array of all the traits used by a given class, including its traits and any base classes. It is similar to the trait_uses_recursive function. However, please note that this function does not work on class instances and will throw an ErrorException if a class instance is provided as an argument.
Laravel 5: Get the Current Date With today

Apr 15, 2018

The today helper function is used to get the current date component of a Carbon instance. It returns a Carbon object with the time component set to 00:00:00. An optional timezone parameter can be supplied to adjust the timezone of the returned instance. For example, you can use this function to get the current day of the year or the day of the week in a specific timezone.

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.