helper class in laravel code example
Example 1: laravel add utility class
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/helpers.php"
]
},
Example 2: how to share a helper globally laravel
'App\Providers\HelperServiceProvider',
Example 3: laravel helper functions
$callback = function ($value) {
return (is_numeric($value)) ? $value * 2 : 0;
};
$result = with(5, $callback);
$result = with(null, $callback);
$result = with(5, null);
Example 4: laravel helper
use Illuminate\Support\Str;
$length = Str::length('Laravel');