/** * Méthode permettant d'enregistrer une catégorie * @param $category La catégorie à enregistrer * @return void */ public function save(Category $category) { if ($category->isValid()) { $category->isNew() ? $this->add($category) : $this->modify($category); } else { throw new RuntimeException('La catégorie doit être valide pour être enregistrée'); } }
/** * 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); } }