Laravel 4 - Reading configuration files

How can I read configuration files from laravel? For example, to connect to the database (app / config / database / .php)

I want mysql data from configuration.

For the package, you do it like this:

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

But how to do this for core files?

+3
source share
2 answers

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

+6
source

To get the database connection parameters (server, username, password, etc.), if you use 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 direct application! But if this is only for your information on the local development machine, you should be fine.

If you are not using MySQL, just replace mysql with sqlite or pgsql or something else.

+5
source

Source: https://habr.com/ru/post/987250/


All Articles