I have the Laravel Administrator Plugin and I set up a setting administrator page that is located in:
The application can store the data, but when i try to get some data in one of my controllers like this:
I can get a returned value… Always null or array 0.
How I can get those configuration values?
You can use a file path rather than dot notation for file paths:
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
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.
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:
I ran into a very similar problem when using this Laravel-Excel package.
The solution I needed was slightly different to the solution above.
I needed to take advantage of Laravel’s config overriding feature to have one config setting for normal execution and a different one for testing. Specifically, I normally wanted Excel files to be stored in
storage/excel and I wanted them to be put in
storage/testing/excel under testing.
The technique of using a slashed path didn’t work because it points to a specific file so didn’t respect the different environments:
$directory = Config::get('packages/maatwebsite/excel/export.store.path');
The solution was to use a package prefix so that the config loader would respect the environment:
$directory = Config::get('excel::export.store.path');
I’m not exactly sure where the
excel shorthand name comes from but I suspect it’s something to do with the Excel facade in the package exposing itself as