Laravel build global function in helpers
Example 1: app()
if (! function_exists('app')) {
/**
* Get the available container instance.
*
* @param string $make
* @param array $parameters
* @return mixed|\Illuminate\Foundation\Application
*/
function app($make = null, $parameters = [])
{
if (is_null($make)) {
return Container::getInstance();
}
return Container::getInstance()->make($make, $parameters);
}
}
Example 2:
if (! function_exists('dd')) {
/**
* Dump the passed variables and end the script.
*
* @param mixed
* @return void
*/
function dd()
{
array_map(function ($x) {
(new Dumper)->dump($x);
}, func_get_args());
die(1);
}
}
Resource (Depend on versions):
Example version 5.3:
Foundation helpers: vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
Support helpers: vendor/laravel/framework/src/Illuminate/Support/helpers.php
Example version 7.0
Reference