Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a PHP file Array

Tags:

php

laravel

What I need to achieve is very simple logically, I use Laravel framework and need my users to be able to change few settings directly from a form rather than opening the settings file which look like this :

<?php

return array(

    'driver' => 'gd'

);

So the question would be how to access a php array file based on key, an update the value ?

like image 751
Richard Delay Avatar asked Aug 24 '26 00:08

Richard Delay


1 Answers

After getting settings with

$settings = require "settings.php";

You can populate the form and get changes submitted back. After you get ALL of the settings into $settings (not just the changed settings, all of 'em), you can write them back with

$php = "<?php return " . var_export($settings,true) . ";";
file_put_contents("settings.php", $php);
like image 149
BareNakedCoder Avatar answered Aug 25 '26 14:08

BareNakedCoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!