phpvms/app/Http/Controllers/Admin/SettingsController.php

46 lines
1.0 KiB
PHP
Raw Normal View History

2017-06-21 07:49:45 +08:00
<?php
namespace App\Http\Controllers\Admin;
2017-12-31 00:38:18 +08:00
use Log;
2017-06-21 07:49:45 +08:00
use Illuminate\Http\Request;
2017-12-31 00:38:18 +08:00
use App\Models\Setting;
2017-06-21 07:49:45 +08:00
class SettingsController extends BaseController
{
2017-06-21 11:48:16 +08:00
/**
2017-12-31 00:38:18 +08:00
* Display the settings. Group them by the setting group
2017-06-21 11:48:16 +08:00
*/
public function index()
{
2017-12-31 00:38:18 +08:00
$settings = Setting::orderBy('order', 'asc')->get();
$settings = $settings->groupBy('group');
2017-06-21 11:48:16 +08:00
return view('admin.settings.index',[
2017-12-31 00:38:18 +08:00
'grouped_settings' => $settings,
]);
2017-06-21 11:48:16 +08:00
}
/**
* Update the specified setting in storage.
2017-06-21 07:49:45 +08:00
*/
2017-12-31 00:38:18 +08:00
public function update(Request $request)
2017-06-21 11:48:16 +08:00
{
2017-12-31 00:38:18 +08:00
foreach($request->post() as $id => $value) {
$setting = Setting::find($id);
if(!$setting) {
continue;
}
Log::info('Updating "'.$setting->key.'" from "'.$setting->value.'" to "'.$value.'"');
$setting->value = $value;
$setting->save();
}
2017-06-21 07:49:45 +08:00
2017-12-31 00:38:18 +08:00
flash('Settings saved!');
return redirect('/admin/settings');
2017-06-21 11:48:16 +08:00
}
2017-06-21 07:49:45 +08:00
}