In my config/app.php file, I have added some variable and I have used these variable in my controller and view files. See below variables:
'META_TITLE' => 'title'
'META_KEYWORDS' => 'keyword'
'META_DESCRIPTION' => 'description'
and I have used these variables like this Config::get("app.META_TITLE")
But I want to override those variable in any of my controller as per requirement.
Laravel stores all the config file values into one single array. So, the "Laravel way" of overwriting the config variables after they are set is to edit the array in which they are stored:
config([
// overwriting values set in config/app.php
'app.META_TITLE' => 'new meta title',
'app.META_KEYWORDS' => 'new meta keywords',
'app.META_DESCRIPTION' => 'new meta description',
// in case you would like to overwrite values inside config/services.php
'services.facebook.client_id' => 'client id',
'services.facebook.client_secret' => 'client secret',
]);
With this concept you can edit any variable set in any config file - just specify which config file they are stored in.
To set configuration values at runtime, pass an array to the
config
helper:
config(['app.timezone' => 'America/Chicago']);
But note that if you want to override environment variables in Dusk, this approach helps: https://laracasts.com/discuss/channels/testing/how-to-change-env-variable-config-in-dusk-test?page=1#reply=475548
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With