/** * Creates or updates a setting value. * * @param string $name * @param string $value * * @return void */ public function set($name, $value) { // save the change to the db $this->model->updateOrCreate(compact('name'), compact('value')); // if we've loaded the settings, persist this change if ($this->settings) { $this->settings[$name] = $value; } }
/** * Seed the settings table. */ protected function seedSettings() { $defaultSettings = [['name' => 'app_name', 'value' => 'Gitamin Demo'], ['name' => 'app_domain', 'value' => 'https://demo.gitamin.com'], ['name' => 'app_locale', 'value' => 'en'], ['name' => 'app_timezone', 'value' => 'Asia/Shanghai'], ['name' => 'app_issue_days', 'value' => '7']]; foreach ($defaultSettings as $setting) { Setting::create($setting); } }
/** * Updates the system settings. * * @return \Illuminate\View\View */ public function postSettings() { $redirectUrl = Session::get('redirect_to', route('admin.settings.general')); if (Request::get('remove_banner') === '1') { $setting = Setting::where('name', 'app_banner'); $setting->delete(); } if (Request::hasFile('app_banner')) { $file = Request::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::to($redirectUrl)->withErrors(trans('admin.settings.general.too-big', ['size' => $maxSize])); } if (!$file->isValid() || $file->getError()) { return Redirect::to($redirectUrl)->withErrors($file->getErrorMessage()); } if (!starts_with($file->getMimeType(), 'image/')) { return Redirect::to($redirectUrl)->withErrors(trans('admin.settings.general.images-only')); } // Store the banner. Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]); // Store the banner type Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]); } try { foreach (Request::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) { Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]); } } catch (Exception $e) { return Redirect::to($redirectUrl)->withErrors(trans('admin.settings.edit.failure')); } if (Request::has('app_locale')) { Lang::setLocale(Request::get('app_locale')); } return Redirect::to($redirectUrl)->withSuccess(trans('admin.settings.edit.success')); }
/** * Handles the actual app install, including user, settings and env. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ public function postStep3() { $postData = Request::all(); $v = Validator::make($postData, ['env.cache_driver' => 'required|in:' . implode(',', array_keys($this->cacheDrivers)), 'env.session_driver' => 'required|in:' . implode(',', array_keys($this->cacheDrivers)), 'settings.app_name' => 'required', 'settings.app_domain' => 'required', 'settings.app_timezone' => 'required', 'settings.app_locale' => 'required', 'user.username' => ['required', 'regex:/\\A(?!.*[:;]-\\))[ -~]+\\z/'], 'user.email' => 'email|required', 'user.password' => 'required']); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => 1]); Auth::login($user); $settings = array_pull($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { Setting::create(['name' => $settingName, 'value' => $settingValue]); } $envData = array_pull($postData, 'env'); // Write the env to the .env file. foreach ($envData as $envKey => $envValue) { $this->writeEnv($envKey, $envValue); } Session::flash('install.done', true); if (Request::ajax()) { return Response::json(['status' => 1]); } return Redirect::to('dashboard'); } if (Request::ajax()) { return Response::json(['errors' => $v->getMessageBag()], 400); } return Redirect::route('install.index')->withInput()->withErrors($v->getMessageBag()); }
/** * Seed the settings table. * * @return void */ protected function seedSettings() { $defaultSettings = [['name' => 'app_name', 'value' => 'Gitamin Demo'], ['name' => 'app_domain', 'value' => 'https://demo.gitaminhq.io'], ['name' => 'app_locale', 'value' => 'en'], ['name' => 'app_timezone', 'value' => 'Europe/London'], ['name' => 'app_issue_days', 'value' => '7']]; Setting::truncate(); foreach ($defaultSettings as $setting) { Setting::create($setting); } }