最简单的解决方案可能是在初始配置文件中使用占位符:
'mysql' => array(
'driver' => 'mysql',
'host' => '%host%',
'database' => '%database%',
'username' => '%username%',
'password' => '%password%',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
然后用实际值替换它们:
$path = app_path('config/database.php');
$contents = File::get($path);
$contents .= str_replace('%host%', $host, $contents);
// and so on
File::put($path, $contents);
这样您就不必实际解析文件.
您可能还想使用某种默认的database.php.dist,并在填写值时创建实际的database.php.这样,您始终可以使用原始.dist文件重复设置过程.