Reputation: 3202
I have created Helper function in
lumen\app\Helpers\Helpers.php
and added
<?php
if(!function_exists('config_path'))
{
/**
* Return the path to config files
* @param null $path
* @return string
*/
function config_path($path=null)
{
return app()->getConfigurationPath(rtrim($path, ".php"));
}
}
in compoer.json
,
"files": [
"app/Helpers/Helpers.php"
],
then ran
composer dump-autoload -o
composer dump-autoload
after that if try to call in web.php
$app->get('/', function () use ($app) {
echo config_path();
});
Getting following error
Fatal error: Call to undefined function config_path() in D:\xampp\htdocs\lumen\routes\web.php on line 17
Upvotes: 1
Views: 1259
Reputation: 163758
Looks like web.php
is executed before Helpers.php
. The best thing you can do is to put any logic into the Controller, Models etc and keep routes only in web.php
.
If you don't care about this, you can require()
helpers file in index.php
, but again, it's a bad practice.
Upvotes: 1