1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Actions\ActivityType;
4 use BookStack\Auth\User;
5 use BookStack\Uploads\ImageRepo;
6 use Illuminate\Http\Request;
8 class SettingController extends Controller
13 * SettingController constructor.
15 public function __construct(ImageRepo $imageRepo)
17 $this->imageRepo = $imageRepo;
18 parent::__construct();
22 * Display a listing of the settings.
24 public function index()
26 $this->checkPermission('settings-manage');
27 $this->setPageTitle(trans('settings.settings'));
29 // Get application version
30 $version = trim(file_get_contents(base_path('version')));
32 return view('settings.index', [
33 'version' => $version,
34 'guestUser' => User::getDefault()
39 * Update the specified settings in storage.
41 public function update(Request $request)
43 $this->preventAccessInDemoMode();
44 $this->checkPermission('settings-manage');
45 $this->validate($request, [
46 'app_logo' => 'nullable|' . $this->getImageValidationRules(),
49 // Cycles through posted settings and update them
50 foreach ($request->all() as $name => $value) {
51 $key = str_replace('setting-', '', trim($name));
52 if (strpos($name, 'setting-') !== 0) {
55 setting()->put($key, $value);
58 // Update logo image if set
59 if ($request->hasFile('app_logo')) {
60 $logoFile = $request->file('app_logo');
61 $this->imageRepo->destroyByType('system');
62 $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
63 setting()->put('app-logo', $image->url);
66 // Clear logo image if requested
67 if ($request->get('app_logo_reset', null)) {
68 $this->imageRepo->destroyByType('system');
69 setting()->remove('app-logo');
72 $section = $request->get('section', '');
73 $this->logActivity(ActivityType::SETTINGS_UPDATE, $section);
74 $this->showSuccessNotification(trans('settings.settings_save_success'));
75 $redirectLocation = '/settings#' . $section;
76 return redirect(rtrim($redirectLocation, '#'));