The Blog

Laravel

Laravel Helper Function: csrf_token

John Koster
John Koster
November 20, 2016

The csrf_token() function in PHP is used to retrieve the CSRF token from the session storage. The token is a random 40-character string generated using the str_random(40) function. It can be used to enhance the security of HTML forms by including it as a hidden input field.

Laravel

Laravel Helper Function: decrypt

John Koster
John Koster
November 20, 2016

The decrypt helper function allows you to easily decrypt a given value. It resolves the configured Encrypter implementation and calls the decrypt method on it. Whether you use the Crypt facade or the decrypt helper function directly, the result will be the same.

Laravel

Laravel Helper Function: encrypt

John Koster
John Koster
November 20, 2016

Learn how to use the encrypt helper function in Laravel to encrypt a given value. This function resolves the configured Encrypter implementation from the Service Container and then calls the encrypt method on the Encrypter instance. Take a look at some example code to see how to use the encrypt helper with the Crypt facade or directly.

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.

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