Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get config data in laravel in a subfolder

Tags:

php

laravel

I have the Laravel Administrator Plugin and I set up a setting administrator page that is located in:

app/config/administrator/settings/site.php

The application can store the data, but when i try to get some data in one of my controllers like this:

Config::get('administrator.settings.site')

I can get a returned value... Always null or array 0.

How I can get those configuration values?

like image 212
Sergio Magoo Quintero Avatar asked Jul 08 '13 17:07

Sergio Magoo Quintero


People also ask

How to get value from config file in Laravel?

How to Access Config Value in Laravel? Hello Dev’s, Today now in this Example,I will show you how to get value from config file in laravel application . We can simply get config value in our laravel application. Here we will use config () method in controller then get config file value in our controller.

How do I install Laravel in a subfolder?

To install Laravel in a subfolder let’s walk through a typical server setup to demonstrate it. Typically the path to the web root is something like this, but it can vary depending on your host: With this path, the “html” folder is the web root, and your domain will typically point here.

How to hide DOT files in Laravel?

Not only this but the .git files as well that can expose other sensitive data. If you have Laravel installed in a subfolder, please check that none of the dot files or the other directories are accessible through the browser, and if they are you can hide them by moving the out of the web root, or using .htaccess on Apache, or Nginx config.

What is the default Laravel env file?

Laravel's default .env file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the config directory using Laravel's env function.


1 Answers

Solution:

You can use a file path rather than dot notation for file paths:

Config::get('administrator/settings/site.variable_name');

Some Explanation

Dot notation is used to get variables inside the config array within a file, rather than to denote file paths.

Therefore you can use Config::get('administrator/settings/site.variable_name'); to get $variable_name from administrator/settings/site.php, or ENV_DIR_NAME/administrator/settings/site.php depending on your environment.

Directories within in app/config are read as environments. For example app/development/database.php will work with Config::get('database.whatever') when you're in your "development" environment while app/production/database.php will be read with Config::get('database.whatever') when you're in the "production" environment.

Laravel falls back to the config/config/*.php file when no environment-specific file is present.

Note

I believe that admin package has a config file in app/config/packages/frozennode/administrator/administrator.php which the package would like you to use for it's settings. That should be available using this convention: Config::get('package::file.option');

like image 171
fideloper Avatar answered Oct 25 '22 07:10

fideloper