I have created a file in the path app/Helpers/helper.php
where I want to include the helpers I need for my project in lumen, at the moment I have this code
<?php
namespace App\Helpers;
/**
* Generate a "random" alpha-numeric string.
*
* @param int $length
* @return string
*
* @throws \RuntimeException
*/
function randomStr($length = 60)
{
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new RuntimeException('OpenSSL extension is required.');
}
$bytes = openssl_random_pseudo_bytes($length * 2);
if ($bytes === false) {
throw new RuntimeException('Unable to generate random string.');
}
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
}
In the file composer.json I added the following key
"files": [
"app/Helpers/Helper.php"
],
And to make the call to the function I do it from a controller in this way
$token = \App\Helpers\randomStr(30);
And the error I get is
Call to undefined function App \ Helpers \ randomStr ()