public function updateProductCategory() { if (Input::has('pk')) { if (!Request::ajax()) { return App::abort(404); } return self::updateQuickEdit(); } $prevURL = Request::header('referer'); if (!Request::isMethod('post')) { return App::abort(404); } if (Input::has('id')) { $create = false; try { $category = ProductCategory::findorFail((int) Input::get('id')); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { return App::abort(404); } $message = 'has been updated successful'; } else { $create = true; $category = new ProductCategory(); $message = 'has been created successful'; } $category->name = Input::get('name'); $category->short_name = Str::slug($category->name); $category->parent_id = (int) Input::get('parent_id'); $category->order_no = (int) Input::get('order_no'); $category->active = Input::has('active') ? 1 : 0; $category->meta_title = e(Input::get('meta_title')); $category->meta_description = e(Input::get('meta_description')); $pass = $category->valid(); if ($pass->passes()) { $action = Input::has('on_menu') ? 'add' : 'delete'; $category = Menu::updateMenu($category, $action, 'collections/'); $category->save(); $imageId = 0; if (Input::hasFile('image')) { $imageId = VIImage::upload(Input::file('image'), public_path() . DS . 'assets' . DS . 'images' . DS . 'product_categories', 450, false); } else { if (Input::has('choose_image')) { $imageId = Input::get('choose_image'); } } if ($imageId) { $category->images()->detach(); $category->images()->attach($imageId); } if (Input::has('continue')) { if ($create) { $prevURL = URL . '/admin/categories/edit-category/' . $category->id; } return Redirect::to($prevURL)->with('flash_success', "<b>{$category->name}</b> {$message}."); } return Redirect::to(URL . '/admin/categories')->with('flash_success', "<b>{$category->name}</b> {$message}."); } return Redirect::to($prevURL)->with('flash_error', $pass->messages()->all())->withInput(); }