Heimdall/app/Http/Controllers/SettingsController.php

103 lines
2.4 KiB
PHP
Raw Normal View History

2018-02-04 20:50:59 +00:00
<?php
namespace App\Http\Controllers;
2018-02-04 21:28:11 +00:00
use Illuminate\Http\Request;
2018-02-04 20:50:59 +00:00
use App\Setting;
use App\SettingGroup;
use App\Http\Controllers\Controller;
class SettingsController extends Controller
{
/**
* @return \Illuminate\View\View
*/
public function index()
{
$settings = SettingGroup::with([
'settings',
])->orderBy('order', 'ASC')->get();
return view('settings.list')->with([
'groups' => $settings,
]);
}
/**
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function edit($id)
{
$setting = Setting::find($id);
if((bool)$setting->system === true) return abort(404);
2018-02-04 20:50:59 +00:00
if (!is_null($setting)) {
return view('settings.edit')->with([
'setting' => $setting,
]);
} else {
return redirect()->route('settings.list')->with([
2018-02-07 13:37:40 +00:00
'error' => __('app.alert.error.not_exist'),
2018-02-04 20:50:59 +00:00
]);
}
}
/**
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
*/
2018-02-04 21:28:11 +00:00
public function update(Request $request, $id)
2018-02-04 20:50:59 +00:00
{
$setting = Setting::find($id);
if (!is_null($setting)) {
$data = Setting::getInput();
if ($setting->type == 'image') {
2018-02-04 21:28:11 +00:00
if($request->hasFile('value')) {
$path = $request->file('value')->store('backgrounds');
$setting->value = $path;
2018-02-04 20:50:59 +00:00
}
2018-02-04 21:28:11 +00:00
2018-02-04 20:50:59 +00:00
} else {
$setting->value = $data->value;
}
$setting->save();
2018-02-04 21:28:11 +00:00
return redirect()->route('settings.index')->with([
2018-02-07 13:37:40 +00:00
'success' => __('app.alert.success.setting_updated'),
2018-02-04 20:50:59 +00:00
]);
} else {
2018-02-04 21:28:11 +00:00
return redirect()->route('settings.index')->with([
2018-02-07 13:37:40 +00:00
'error' => __('app.alert.error.not_exist'),
2018-02-04 20:50:59 +00:00
]);
}
}
/**
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function clear($id)
{
$setting = Setting::find($id);
if((bool)$setting->system !== true) {
$setting->value = '';
$setting->save();
}
return redirect()->route('settings.index')->with([
2018-02-07 13:37:40 +00:00
'success' => __('app.alert.success.setting_updated'),
]);
}
2018-02-04 20:50:59 +00:00
}