2018-02-04 20:50:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2022-03-19 13:54:32 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2018-02-04 20:50:59 +00:00
|
|
|
use App\Setting;
|
|
|
|
use App\SettingGroup;
|
2018-10-15 12:02:16 +00:00
|
|
|
use App\User;
|
2022-03-19 13:54:32 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-10-15 12:02:16 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2018-02-04 20:50:59 +00:00
|
|
|
|
|
|
|
class SettingsController extends Controller
|
|
|
|
{
|
2018-10-15 12:02:16 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2018-10-15 13:35:14 +00:00
|
|
|
$this->middleware('allowed');
|
2018-10-15 12:02:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 20:50:59 +00:00
|
|
|
/**
|
|
|
|
* @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);
|
2018-10-14 15:17:55 +00:00
|
|
|
//die("s: ".$setting->label);
|
2018-02-04 20:50:59 +00:00
|
|
|
|
2022-03-19 13:54:32 +00:00
|
|
|
if ((bool) $setting->system === true) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2018-02-05 14:21:54 +00:00
|
|
|
|
2022-03-19 13:54:32 +00:00
|
|
|
if (! is_null($setting)) {
|
2018-02-04 20:50:59 +00:00
|
|
|
return view('settings.edit')->with([
|
|
|
|
'setting' => $setting,
|
|
|
|
]);
|
|
|
|
} else {
|
2019-06-18 09:51:51 +00:00
|
|
|
$route = route('settings.list', []);
|
2022-03-19 13:54:32 +00:00
|
|
|
|
|
|
|
return redirect($route)
|
2018-02-18 22:36:32 +00:00
|
|
|
->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);
|
2018-10-14 15:17:55 +00:00
|
|
|
$user = $this->user();
|
2018-02-04 20:50:59 +00:00
|
|
|
|
2022-03-19 13:54:32 +00:00
|
|
|
if (! is_null($setting)) {
|
2022-03-10 11:54:29 +00:00
|
|
|
$data = Setting::getInput($request);
|
2018-02-04 20:50:59 +00:00
|
|
|
|
2018-11-06 09:20:53 +00:00
|
|
|
$setting_value = null;
|
|
|
|
|
2018-02-04 20:50:59 +00:00
|
|
|
if ($setting->type == 'image') {
|
2022-03-19 13:54:32 +00:00
|
|
|
if ($request->hasFile('value')) {
|
2018-02-04 21:28:11 +00:00
|
|
|
$path = $request->file('value')->store('backgrounds');
|
2018-10-14 15:17:55 +00:00
|
|
|
$setting_value = $path;
|
2018-02-04 20:50:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-10-14 15:17:55 +00:00
|
|
|
$setting_value = $data->value;
|
2018-02-04 20:50:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 15:00:20 +00:00
|
|
|
$user->settings()->detach($setting->id);
|
|
|
|
$user->settings()->save($setting, ['uservalue' => $setting_value]);
|
2022-03-19 13:54:32 +00:00
|
|
|
|
2019-06-18 09:51:51 +00:00
|
|
|
$route = route('settings.index', []);
|
2022-03-19 13:54:32 +00:00
|
|
|
|
|
|
|
return redirect($route)
|
2018-02-18 22:36:32 +00:00
|
|
|
->with([
|
2018-02-07 13:37:40 +00:00
|
|
|
'success' => __('app.alert.success.setting_updated'),
|
2018-02-04 20:50:59 +00:00
|
|
|
]);
|
|
|
|
} else {
|
2019-06-18 09:51:51 +00:00
|
|
|
$route = route('settings.index', []);
|
2022-03-19 13:54:32 +00:00
|
|
|
|
|
|
|
return redirect($route)
|
2018-02-18 22:36:32 +00:00
|
|
|
->with([
|
2018-02-07 13:37:40 +00:00
|
|
|
'error' => __('app.alert.error.not_exist'),
|
2018-02-04 20:50:59 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2022-03-19 13:54:32 +00:00
|
|
|
|
2018-02-05 14:21:54 +00:00
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function clear($id)
|
|
|
|
{
|
2018-10-15 18:56:45 +00:00
|
|
|
$user = $this->user();
|
2018-02-05 14:21:54 +00:00
|
|
|
$setting = Setting::find($id);
|
2022-03-19 13:54:32 +00:00
|
|
|
if ((bool) $setting->system !== true) {
|
2018-10-15 18:56:45 +00:00
|
|
|
$user->settings()->detach($setting->id);
|
|
|
|
$user->settings()->save($setting, ['uservalue' => '']);
|
2018-02-05 14:21:54 +00:00
|
|
|
}
|
2019-06-18 09:51:51 +00:00
|
|
|
$route = route('settings.index', []);
|
2022-03-19 13:54:32 +00:00
|
|
|
|
|
|
|
return redirect($route)
|
2018-02-18 22:36:32 +00:00
|
|
|
->with([
|
2018-02-07 13:37:40 +00:00
|
|
|
'success' => __('app.alert.success.setting_updated'),
|
2018-02-05 14:21:54 +00:00
|
|
|
]);
|
|
|
|
}
|
2019-01-18 15:21:50 +00:00
|
|
|
|
|
|
|
public function search(Request $request)
|
|
|
|
{
|
|
|
|
}
|
2018-02-04 20:50:59 +00:00
|
|
|
}
|