In Laravel 5

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.
Laravel 5: Getting Array or Object Values With data_get

Apr 15, 2018

The data_get function is a versatile tool that allows you to retrieve values from both objects and arrays in PHP. It has the same behavior as the array_get and object_get functions, but it accepts both objects and arrays as its $target input value. You can also supply a default value to use if the key doesn't exist in the target. The function is easy to use and can greatly simplify your code when working with both objects and arrays.
Laravel 5: Getting the Class Name for an Object Instance With class_basename

Apr 15, 2018

Learn how to use the class_basename function in PHP to retrieve the name of a class. The function accepts a class and returns its base name. Check out the provided examples to see how it works with different classes and objects.
Laravel 5: Getting the Current Date and Time With now

Apr 15, 2018

The now helper function in PHP returns a new Carbon instance that represents the current date and time. It can also accept an optional timezone parameter to adjust the timezone of the returned date. Learn how to use the now helper function with an example that shows how to get the current Atom formatted date and time, as well as how to get the current date and time for a specific timezone.
Laravel 5: Provide Default Values for Object Properties With optional

Apr 15, 2018

The optional function in Laravel returns a new instance of Illuminate\Support\Optional with the provided value. It allows you to easily retrieve a default or null value on method return values or object properties that may not exist. This can be useful when displaying data or returning results that might not exist at runtime. The Optional class also implements the Illuminate\Support\Traits\Macroable trait, allowing you to add functionality to the Optional instance at runtime.

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.