The Blog

Laravel

Laravel

Laravel Helper Function: env

John Koster
John Koster
November 20, 2016

The env function in Laravel retrieves the value of an environment variable, returning the value if it exists or a default value if it does not. It supports automatic conversion of boolean string representations and null values to their respective PHP types. Examples are shown using a .env file, demonstrating the function's usage and defaults.

Laravel

Laravel Helper Function: info

John Koster
John Koster
November 20, 2016

The info helper function in Laravel allows you to write information entries into the log files. You can specify a message and an optional context, which can be an array of data. The context can even contain objects. The log entries will include the message and the context data if provided.

Laravel

Laravel Helper Function: logger

John Koster
John Koster
November 20, 2016

The logger helper function in Laravel is a powerful tool for logging messages. If no message is provided, the function returns a Log instance. When used to write log messages, you can pass both a message and a context. The context can be an array, and even contain arrays or objects within it. The function will output log messages in Laravel's log files.

Laravel

Laravel Helper Function: session

John Koster
John Koster
November 20, 2016

The session function in Laravel is a versatile function that can be used to return an instance of the SessionManager class, set session values, and retrieve session values. To return an instance of the SessionManager class, simply call the function without any parameters. To set session values, pass in an array of key/value pairs or use the put method to set a single session value. To retrieve session values, pass in the desired key to the function. If a session value does not exist, the function will return null, unless a default value is specified.

Laravel

Laravel Array Helper Function: array_first

John Koster
John Koster
November 19, 2016

The first helper method in Laravel is used to retrieve the first key/value pair in an array that satisfies a given callback function. The callback function can be used to check if a value matches a specific format. If no key/value pair satisfies the callback function, a default value can be returned. The callback parameter is optional, and if omitted, the method will return the first item in the array. Additionally, there is a shortcut function called array_first which is equivalent to calling Arr::first.

Laravel

Laravel Array Helper Function: array_forget

John Koster
John Koster
November 19, 2016

The forget helper method in Laravel is used to remove items from an array using dot notation. It is a mutable function that affects the original array. You can remove single or multiple items by passing the keys as a string or an array. There is also a shortcut function called array_forget available in the global namespace.

Laravel

Laravel Array Helper Function: array_get

John Koster
John Koster
November 19, 2016

The get helper method allows developers to quickly retrieve items from an array using dot notation, instead of PHP's array syntax. It is easier to read and can be customized with a default value. The array_get function is a shortcut to calling the Arr::get method in the global namespace.

Laravel

Laravel Array Helper Function: array_has

John Koster
John Koster
November 19, 2016

The has helper method in Laravel allows you to check if a specific key exists in an array using dot notation. It returns a boolean value indicating the existence of the key. This method is particularly useful for arrays with arbitrary depth and is easier to use than PHP's isset function. Additionally, there is a shortcut function called array_has that can be used instead of calling Arr::has.

Laravel

Laravel Array Helper Function: array_last

John Koster
John Koster
November 19, 2016

The last helper method in Laravel is used to retrieve the last element in an array that satisfies the given callback function. If no value satisfies the callback, a default value can be provided as well. An example usage of this method is demonstrated, showing how to get the last post from an array based on a specific format. The optional callback parameter can be omitted, in which case the method will simply return the last item in the array. Additionally, there is a shortcut function called array_last available in the global namespace that performs the same functionality as Arr::last.

Laravel

Laravel Array Helper Function: array_pluck

John Koster
John Koster
November 19, 2016

The pluck helper method is a convenient way to extract specific values from an array. It can be used with arrays of objects or arrays of arrays. The method can also return an array with a key/value pair based on the specified key. Additionally, pluck supports dot notation to search for keys at arbitrary depths in nested arrays or objects. There is also a global array_pluck function, which is a shortcut to calling Arr::pluck.

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