2

I'm looking for a way to write to laravel 5 configuration files, in a cleaner and easier way then using the good old str_replace.

There are laravel 4 solutions: How to edit and save custom config files in Laravel? and: https://github.com/daftspunk/laravel-config-writer

But this is not working in laravel 5.

Community
  • 1
  • 1
Nicolas Widart
  • 1,187
  • 4
  • 13
  • 30
  • What from those provided solutions didn't work? Did you encounter an error, did it not update the file? – Chris Apr 11 '15 at 14:33
  • Those solutions do not work with laravel 5. Laravel 5 has other method signatures. FileLoader is no more under the Config namespace but `Translation` now. The config/Repository has other constructor arguments, etc. etc. – Nicolas Widart Apr 11 '15 at 15:57
  • 1
    Solution I've used at the moment: set the settings on runtime in the ioc container. – Nicolas Widart Apr 11 '15 at 19:55

1 Answers1

1

From version 5.1 you are able to do next for changing any config file:

config(['YOUR-CONFIG.YOUR_KEY' => 'NEW_VALUE']);
$text = '<?php return ' . var_export(config('YOUR-CONFIG'), true) . ';';
file_put_contents(config_path('YOUR-CONFIG.php'), $text);
Mykola Vasilaki
  • 416
  • 6
  • 11