/**
  * Create new category or update existing one.
  * 
  * @param  array  $input
  * @return void
  */
 public function createOrUpdate(array $input)
 {
     $snakeInput = array();
     //convert all input keys to snake case
     foreach ($input as $k => $v) {
         $snakeInput[snake_case($k)] = $v;
     }
     //find a model if we get passed an id
     if (isset($snakeInput['id'])) {
         $this->model = $this->model->find($snakeInput['id']);
     }
     $this->model->fill($snakeInput)->save();
     if ($this->model->auto_update) {
         $this->attachByQuery($this->model->id, $this->model->query, $this->model->limit);
     }
     Cache::forget('home.content');
     return true;
 }
 /**
  * @param $id
  * @param $attributes
  * @return bool|mixed
  * @throws \Grace\Exceptions\Validation\ValidationException
  */
 public function update($id, $attributes)
 {
     $this->category = $this->find($id);
     if ($this->isValid($attributes)) {
         $this->category->resluggify();
         $this->category->fill($attributes)->save();
         return true;
     }
     throw new ValidationException('Category validation failed', $this->getErrors());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $category = new Category();
     $data = Input::all();
     // Revisamos si la data es válido
     if ($category->isValid($data)) {
         // Si la data es valida se la asignamos al category
         $category->fill($data);
         // Guardamos el category
         $category->save();
         return Redirect::to('admin/category')->with('success_message', 'El registro ha sido ingresado correctamente.')->withInput();
     } else {
         // En caso de error regresa a la acción create con los datos y los errores encontrados
         return Redirect::back()->withInput()->withErrors($category->errors);
     }
 }