Heimdall/app/Http/Controllers/SettingsController.php
Shift b1dc4d4a41
Apply Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] config to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started.

For more information on customizing the code style applied by Shift, [watch this short video][4].

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://github.com/squizlabs/PHP_CodeSniffer
[3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
[4]: https://laravelshift.com/videos/shift-code-style
2022-03-19 13:54:32 +00:00

129 lines
3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Setting;
use App\SettingGroup;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class SettingsController extends Controller
{
public function __construct()
{
$this->middleware('allowed');
}
/**
* @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);
//die("s: ".$setting->label);
if ((bool) $setting->system === true) {
return abort(404);
}
if (! is_null($setting)) {
return view('settings.edit')->with([
'setting' => $setting,
]);
} else {
$route = route('settings.list', []);
return redirect($route)
->with([
'error' => __('app.alert.error.not_exist'),
]);
}
}
/**
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, $id)
{
$setting = Setting::find($id);
$user = $this->user();
if (! is_null($setting)) {
$data = Setting::getInput($request);
$setting_value = null;
if ($setting->type == 'image') {
if ($request->hasFile('value')) {
$path = $request->file('value')->store('backgrounds');
$setting_value = $path;
}
} else {
$setting_value = $data->value;
}
$user->settings()->detach($setting->id);
$user->settings()->save($setting, ['uservalue' => $setting_value]);
$route = route('settings.index', []);
return redirect($route)
->with([
'success' => __('app.alert.success.setting_updated'),
]);
} else {
$route = route('settings.index', []);
return redirect($route)
->with([
'error' => __('app.alert.error.not_exist'),
]);
}
}
/**
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function clear($id)
{
$user = $this->user();
$setting = Setting::find($id);
if ((bool) $setting->system !== true) {
$user->settings()->detach($setting->id);
$user->settings()->save($setting, ['uservalue' => '']);
}
$route = route('settings.index', []);
return redirect($route)
->with([
'success' => __('app.alert.success.setting_updated'),
]);
}
public function search(Request $request)
{
}
}