Search

In Laravel

Laravel Application Helper: old

Nov 20, 2016

The old helper function is used to retrieve an old input item from a previous request. It accepts a $key argument that should be the name of the input item to retrieve. A $default value can also be supplied to be returned if the given $key does not exist. There are alternative methods to achieve the same result, such as using the Input facade or the request() helper function.
Laravel Application Helper: policy

Nov 20, 2016

Learn how to retrieve a policy instance using the policy helper function in Laravel. This function allows you to retrieve a policy class instance for a given class name or object. If no policies have been registered for the class, an exception will be thrown.
Laravel Application Helper: public_path

Nov 20, 2016

The public_path function in Laravel returns the path to the public directory. It can also be used to construct paths relative to the public directory by providing a $path argument. The function does not automatically add a trailing slash to the final path, but this can be achieved by using the str_finish function in conjunction with public_path.
Laravel Application Helper: response

Nov 20, 2016

The response helper function in Laravel can be used in two ways. When no arguments are provided, it returns an instance of Illuminate\Contracts\Routing\ResponseFactory which allows you to use methods like view or json to generate responses. On the other hand, if you pass arguments to the function, it uses the ResponseFactory::make method to create a new instance of Illuminate\Http\Response. You can also set the status code and add additional headers to the response.
Laravel Application Helper: storage_path

Nov 20, 2016

The storage_path function in Laravel returns the path to the storage directory. If a specific $path is provided, it constructs a path relative to the storage directory. The function does not automatically add a trailing slash to the returned string. To achieve this, you can use the str_finish function with storage_path as its argument. Examples are provided to illustrate its usage.
Laravel Array Helper Function: array_prepend (Easily Add an Item to the Beginning of an Array)

Nov 20, 2016

The prepend helper method allows you to add a value to the beginning of an array. You can optionally specify a key for the new item if the array is associative. The method returns a new modified copy of the original array, leaving the original unchanged. Additionally, there is a shortcut array_prepend helper function available in the global namespace that calls the Arr::prepend method.
Laravel Array Helper Function: array_sort

Nov 20, 2016

The sort helper method allows you to sort an array based on a given condition. The method iterates over the array and passes each value to a callback function, which determines the sort order. In this example, we create a new array of student test scores and use Arr::sort to sort it by either test score or student name. Additionally, there is a shortcut function called array_sort that serves as a global namespace for calling Arr::sort.
Laravel Array Helper Function: array_where

Nov 20, 2016

The where helper method is used to filter an array and create a new array based on a given callback function. It provides the flexibility to filter by both key and value, or just by value, depending on the logic provided in the callback. This method is helpful when you want to selectively extract specific elements from an array. For example, you can filter an array to include only numbers less than or equal to 10, or filter an array to include only students who have passed a test and whose name starts with the letter 'A'. The array_where function is a shorthand for calling Arr::where and is available in the global namespace.
Laravel Array Helper Function: Checking If a Key Exists in an Array or Collection

Nov 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 Array Helper Function: Determining If a Value Is An Array

Nov 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 Array Helper Function: isAssoc (Checking If An Array Is Associative)

Nov 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 Helper Function: bcrypt

Nov 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 Helper Function: config

Nov 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 Helper Function: cookie

Nov 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.