2017-06-21 07:49:45 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Controller;
|
2017-12-31 00:38:18 +08:00
|
|
|
use App\Models\Setting;
|
2019-10-30 21:05:18 +08:00
|
|
|
use Igaster\LaravelTheme\Facades\Theme;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Illuminate\Http\Request;
|
2019-10-30 21:05:18 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2017-06-21 07:49:45 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
class SettingsController extends Controller
|
2017-06-21 07:49:45 +08:00
|
|
|
{
|
2019-10-30 21:05:18 +08:00
|
|
|
/**
|
|
|
|
* Get a list of themes formatted for a select box
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getThemes(): array
|
|
|
|
{
|
|
|
|
$themes = Theme::all();
|
|
|
|
$theme_list = [];
|
|
|
|
foreach ($themes as $t) {
|
|
|
|
if (!$t || !$t->name || $t->name === 'false') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$theme_list[] = $t->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $theme_list;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
return view('admin.settings.index', [
|
2017-12-31 00:38:18 +08:00
|
|
|
'grouped_settings' => $settings,
|
2019-10-30 21:05:18 +08:00
|
|
|
'themes' => $this->getThemes(),
|
2017-12-10 11:21:49 +08:00
|
|
|
]);
|
2017-06-21 11:48:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified setting in storage.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-21 12:33:09 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-21 12:33:09 +08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
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
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
foreach ($request->post() as $id => $value) {
|
2017-12-31 00:38:18 +08:00
|
|
|
$setting = Setting::find($id);
|
2018-03-20 09:50:40 +08:00
|
|
|
if (!$setting) {
|
2017-12-31 00:38:18 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-09-04 16:11:51 +08:00
|
|
|
if ($setting->type == 'bool' || $setting->type == 'boolean') {
|
|
|
|
$value = get_truth_state($value);
|
|
|
|
}
|
|
|
|
|
2018-01-12 09:46:35 +08:00
|
|
|
Log::info('Updating "'.$setting->id.'" from "'.$setting->value.'" to "'.$value.'"');
|
2017-12-31 00:38:18 +08:00
|
|
|
$setting->value = $value;
|
|
|
|
$setting->save();
|
|
|
|
}
|
2017-06-21 07:49:45 +08:00
|
|
|
|
2017-12-31 00:38:18 +08:00
|
|
|
flash('Settings saved!');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2017-12-10 11:56:26 +08:00
|
|
|
return redirect('/admin/settings');
|
2017-06-21 11:48:16 +08:00
|
|
|
}
|
2017-06-21 07:49:45 +08:00
|
|
|
}
|