/**
  * Validate and save changes.
  *
  * @return Response
  */
 public function patchIndex(Request $request)
 {
     if (!$this->user->canAdminConfig()) {
         return abort(403);
     }
     $input = Input::all();
     $optionGroups = OptionGroup::getSiteConfig();
     $requirements = [];
     // From each group,
     foreach ($optionGroups as $optionGroup) {
         // From each option within each group,
         foreach ($optionGroup->options as $option) {
             if (!isset($input[$option->option_name])) {
                 $input[$option->option_name] = null;
             }
             // Pull the validation parameter string,
             $requirements[$option->option_name] = $option->getValidation();
             $input[$option->option_name] = $option->getSanitaryInput($input[$option->option_name]);
         }
     }
     // Build our validator.
     $validator = Validator::make($input, $requirements);
     if ($validator->fails()) {
         return redirect(Request::path())->withErrors($validator->errors()->all())->withInput();
     }
     foreach ($optionGroups as &$optionGroup) {
         foreach ($optionGroup->options as &$option) {
             $setting = SiteSetting::firstOrNew(['option_name' => $option->option_name]);
             $option->option_value = $input[$option->option_name];
             $setting->option_value = $input[$option->option_name];
             $setting->save();
         }
     }
     return $this->view(static::VIEW_CONFIG, ['groups' => $optionGroups]);
 }
Example #2
0
 /**
  * Loads all settings.
  *
  * @return collection
  */
 public function fetchSettings()
 {
     switch (env('CACHE_DRIVER')) {
         case "file":
         case "database":
             return SiteSetting::getAll();
             // We only cache settings when we are using a memory cache.
             // Anything else is slower than the query.
         // We only cache settings when we are using a memory cache.
         // Anything else is slower than the query.
         default:
             return Cache::remember('site.settings', 30, function () {
                 return SiteSetting::getAll();
             });
     }
 }
Example #3
0
 /**
  * Returns an system option's value.
  *
  * @param  string  $option
  * @return string|null
  */
 public function option($option_name)
 {
     if (!isset($this->options)) {
         $this->options = SiteSetting::getAll();
     }
     foreach ($this->options as $option) {
         if ($option->option_name == $option_name) {
             return $option->option_value;
         }
     }
     return null;
 }