Laravel 4 - Read config files

寵の児 提交于 2019-12-10 16:17:57

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/17132206/laravel-4-read-config-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!