TheNiceGuy
TheNiceGuy

Reputation: 3730

Laravel 4 - Read config files

How can i read the config files from laravel? For example for the database connection (app/config/database/.php)

I want the mysql data from the config.

For a package you do it like that:

return Config::get('package::group.option');

But how to do it for the main files?

Upvotes: 4

Views: 9509

Answers (2)

Brendan White
Brendan White

Reputation: 453

To get the database connection parameters (server, username, password etc) if you're using MySQL, you can do this:

echo "Driver: " . Config::get('database.connections.mysql.driver') . "<br/>\r\n";
echo "Host: " . Config::get('database.connections.mysql.host') . "<br/>\r\n";
echo "Database: " . Config::get('database.connections.mysql.database') . "<br/>\r\n";
echo "Username: " . Config::get('database.connections.mysql.username') . "<br/>\r\n";
echo "Password: " . Config::get('database.connections.mysql.password') . "<br/>\r\n";

On my local development machine this gives:

Driver: mysql

Host: localhost

Database: local_dev_db

Username: root

Password: not-my-real-pwd

...obviously you should never show your password (or any of these other details) in your live app! But if it's just for your information on a local development machine you should be fine.

If you're not using MySQL, just replace mysql with sqlite or pgsql or whatever.

Upvotes: 6

gmaliar
gmaliar

Reputation: 5479

I do Config::get('database.default') for example.

Upvotes: 8

Related Questions