public function getRules($data) { $rules = []; $groups = Setting::getGroups(); foreach ($groups as $group => $groupSettings) { foreach ($groupSettings as $name => $options) { if (is_array($options['rule'])) { $rule = array_merge(['required'], $options['rule']); } else { $rule = 'required|' . $options['rule']; } $rules[str_replace('.', '_', $name)] = $rule; } } return $rules; }
public static function import($defaults = []) { static::$nameToValue = []; $groups = Setting::getGroups(); $settings = SettingQuery::create()->find(); $nameToValue = $settings->toKeyValue('name', 'value'); foreach ($groups as $group => $groupSettings) { foreach ($groupSettings as $name => $options) { if (!isset($nameToValue[$name])) { $setting = new Setting(); $setting->setName($name)->setValue(array_get($defaults, $name, $options['default'])); $setting->save(); } } } }
public function getSettings() { $settingsForm = new SettingsForm(); $groups = Setting::getGroups(); return View::make('admin.settings', compact('settingsForm', 'groups')); }