The Blog

Laravel 5

Laravel 5

Laravel 5: View Error Bags

John Koster
John Koster
April 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

Laravel 5: Checking if a Variable Holds a Value With filled

John Koster
John Koster
April 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

Laravel 5: Checking if the Script is Executing on a Windows Machine With windows_os

John Koster
John Koster
April 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

Laravel 5: Conditionally Transforming/Changing Values With transform

John Koster
John Koster
April 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

Laravel 5: Determining if a Variable Holds a Value With blank

John Koster
John Koster
April 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

Laravel 5: Determining Which Traits a Class Uses With trait_uses_recursive

John Koster
John Koster
April 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

Laravel 5: Displaying Variable Data and Stopping Script Execution for Debugging With dd

John Koster
John Koster
April 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

Laravel 5: Execute a Callback on a Given Value While Chaining the Original Value With tap

John Koster
John Koster
April 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

Laravel 5: Finding What Traits a Class Uses With class_uses_recursive

John Koster
John Koster
April 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

Laravel 5: Get the Current Date With today

John Koster
John Koster
April 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.

Latest posts

That Escalated Quickly: All the New Things

The past six months or so have been incredibly busy. What started as a new article series about cust...

Read more
Troubleshooting a Statamic Illegal Offset Type Error when Viewing Collection Entries in the Control Panel

In this post I talk about how I resolved a mysterious illegal offset type error when viewing collect...

Read more
Creating Simple HTTP Redirect Routes from a Statamic Site

Generating a custom Laravel routes file from a Statamic website to redirect to a new domain.

Read more
Disabling Vite File Hashes

Disabling file hashes in Vite output can be accomplished by modifying your project's vite.config.js

Read more
Implementing a Custom Laravel Blade Precompiler for Volt and Livewire

Learn how to implement a custom component compiler for Laravel's Blade templating language in this p...

Read more
Creating a Hybrid Cache System for Statamic: Part Five

Part 5 of 6 covers implementing a cache namespace and labeling system, which we can use to target mu...

Read more