public function doUpdate()
{
$resource = opendir(database_path('update_scripts'));
$updateScriptExist = false;
$tips = [];
while ($filename = @readdir($resource)) {
if ($filename != "." && $filename != "..") {
preg_match('/update-(.*)-to-(.*).php/', $filename, $matches);
// skip if the file is not valid or expired
if (!isset($matches[2]) || version_compare($matches[2], config('app.version'), '<')) {
continue;
}
$result = (require database_path('update_scripts') . "/{$filename}");
if (is_array($result)) {
// push tip to array
foreach ($result as $tip) {
$tips[] = $tip;
}
}
$updateScriptExist = true;
}
}
closedir($resource);
foreach (config('options') as $key => $value) {
if (!Option::has($key)) {
Option::set($key, $value);
}
}
if (!$updateScriptExist) {
// if update script is not given
Option::set('version', config('app.version'));
}
return view('setup.updates.success', ['tips' => $tips]);
}