Helpers
Introduction
Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.
Available Methods
Arrays & Objects
array_add array_collapse array_divide array_dot array_except array_first array_flatten array_forget array_get array_has array_last array_only array_pluck array_prepend array_pull array_random array_set array_sort array_sort_recursive array_where array_wrap data_fill data_get data_set head last
Paths
app_path base_path config_path database_path mix public_path resource_path storage_path
Strings
__ camel_case class_basename e ends_with kebab_case preg_replace_array snake_case starts_with str_after str_before str_contains str_finish str_is str_limit Str::orderedUuid str_plural str_random str_replace_array str_replace_first str_replace_last str_singular str_slug str_start studly_case title_case trans trans_choice Str::uuid
URLs
action asset secure_asset route secure_url url
Miscellaneous
abort abort_if abort_unless app auth back bcrypt blank broadcast cache class_uses_recursive collect config cookie csrf_field csrf_token dd decrypt dispatch dispatch_now dump encrypt env event factory filled info logger method_field now old optional policy redirect report request rescue resolve response retry session tap today throw_if throw_unless trait_uses_recursive transform validator value view with
Method Listing
Arrays & Objects
array_add()
The array_add
function adds a given key / value pair to an array if the given key doesn't already exist in the array:
$array = array_add(['name' => 'Desk'], 'price', 100);
// ['name' => 'Desk', 'price' => 100]
array_collapse()
The array_collapse
function collapses an array of arrays into a single array:
$array = array_collapse([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
array_divide()
The array_divide
function returns two arrays, one containing the keys, and the other containing the values of the given array:
[$keys, $values] = array_divide(['name' => 'Desk']);
// $keys: ['name']
// $values: ['Desk']