Skip to content
Advertisement

Laravel custom helper – undefined index SERVER_NAME

In Laravel 5.1, I created a custom helper file: custom.php which I load in composer.json:

JavaScript

and it contains this method:

JavaScript

It works as expected, but every time I do php artisan commands, I get a call stack and this message:

JavaScript

Why is this so? The method returns the correct value when run from within my Laravel app.

Advertisement

Answer

$_SERVER[‘SERVER_Name’] global variable is only accessible when running your application through a browser. It will throw an error when you run your application through php-cli/through the terminal. Change your code to

JavaScript

Hope this helps you.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement