Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling environment variables inside class not working

Tags:

php

laravel

I'm not sure why this isn't working? I want to be able to access the constants set in my .env.php file but NetBeans is showing an error stating that the getenv function isn't recognized.

Here is my code

<?php 

class Blah extends Eloquent {
...
protected $connection = getenv('DB_NAME');
}
like image 991
user3813559 Avatar asked Aug 16 '26 18:08

user3813559


1 Answers

Set the class values from the constructor.

class Blah extends Eloquent
{
    protected $connection = null;

    function __construct() {
        $this->connection = getenv('DB_NAME');
    }
}
like image 111
Jens A. Koch Avatar answered Aug 18 '26 09:08

Jens A. Koch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!