The Blog

Laravel

Laravel

Laravel Array Helper Function: Checking If a Key Exists in an Array or Collection

John Koster
John Koster
November 20, 2016

The exists helper method in Laravel can be used to check if a specified key or index exists in a given array. It is similar to PHP's array_key_exists function. The method requires two parameters: the array to check and the key/index to search for. The method returns true if the key/index exists and false otherwise. The method supports arrays, collections, and other values that return true from the Arr::accessible helper method.

Laravel

Laravel Array Helper Function: Determining If a Value Is An Array

John Koster
John Koster
November 20, 2016

The accessible helper method determines if a given value is array accessible. In other words, it checks if the value is an array or an instance of ArrayAccess. This is useful for checking if a variable can be accessed using array syntax. The method can be used with various types of values, as shown in the provided examples.

Laravel

Laravel Array Helper Function: isAssoc (Checking If An Array Is Associative)

John Koster
John Koster
November 20, 2016

The isAssoc helper method can determine if an array is associative or not. According to the provided documentation, an array is considered associative if it doesn't have sequential numeric keys starting from zero. However, in practice, the behavior can be slightly different. For example, [0,1,2,3] is not considered associative, while ['associative' => 'array'] is.

Laravel

Laravel Helper Function: bcrypt

John Koster
John Koster
November 20, 2016

The bcrypt function in PHP is used to generate a hashed representation of a given value. It accepts an optional array of options which can affect how the hash is computed. Each time bcrypt is called, it will produce a different result, even if the input remains the same. The rounds option can be used to control the number of iterations, with a default value of 10. Increasing the number of rounds will also increase the time required to compute the hash.

Laravel

Laravel Helper Function: config

John Koster
John Koster
November 20, 2016

The config helper function in Laravel is a versatile function that can be used to access, set, and retrieve configuration values. When called without any arguments, it returns an instance of the Illuminate\Config\Repository class, allowing you to check if a config item exists. If you provide an array as the key, you can set multiple configuration values at once. And when you provide a non-array key, you can retrieve a configuration value, with an optional default value if the key doesn't exist. Use this helper function to conveniently handle your application's configuration.

Laravel

Laravel Helper Function: cookie

John Koster
John Koster
November 20, 2016

The cookie function in Laravel is used to create a new instance of the \Symfony\Component\HttpFoundation\Cookie class or return an instance of \Illuminate\Contracts\Cookie \Factory. It does not send the cookie to the client, only creates it. The function has seven optional parameters including the name, value, expiration time, path, domain, secure flag, and httpOnly flag. Examples of creating cookies with different options are provided.

Laravel

Laravel Helper Function: csrf_field

John Koster
John Koster
November 20, 2016

The csrf_field function simplifies the process of generating a hidden HTML element with the CSRF token value. It replaces the need for manually writing the HTML code and can be used in both PHP and Blade syntax. This makes it easier to include CSRF protection in your forms without cluttering your code.

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.

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