Ejemplo n.º 1
0
 public function run()
 {
     $optionTabs = Config::get('option_tabs', []);
     foreach ($optionTabs as $tab) {
         $optionTab = OptionTab::where('slug', $tab['slug'])->get()->first();
         if (empty($optionTab)) {
             $optionTab = new OptionTab();
             $optionTab->slug = $tab['slug'];
             $optionTab->display_name = ucwords(str_replace('_', ' ', $tab['slug']));
             $optionTab->save();
         }
         foreach ($tab['options'] as $name => $value) {
             $checkOption = Option::where('name', $name)->get()->first();
             if (empty($checkOption) && !empty($value)) {
                 $option = new Option();
                 $option->name = $name;
                 $option->display_name = ucwords(str_replace('_', ' ', $name));
                 $option->value = $value;
                 $option->autoload = true;
                 $option->sort_order = 1;
                 $optionTab->options()->save($option);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  * PUT /options/{id}
  *
  * @param  int $id
  *
  * @return Response
  */
 public function update($id)
 {
     $option = Option::findOrFail($id);
     $rules = Option::$rules;
     $rules['name'] = str_replace('{id}', $option->id, $rules['name']);
     $validator = Validator::make($data = Input::all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $option->update($data);
     Cache::tags('option', $option->name)->flush();
     $tab = OptionTab::find($option->option_tab_id);
     if (!empty($tab)) {
         return redirect()->route('admin.options.show', $tab->slug);
     }
     return redirect()->route('admin.options.index');
 }