public function editHandle() { $id = e(Input::get('id')); $category = Category::find($id); $path = DirectoryHelpers::seoString(e(Input::get('path'))); $nice_input_names = ['is_root' => trans('directory.is_root'), 'name' => trans('directory.name'), 'path' => trans('directory.path'), 'description' => trans('directory.description'), 'keywords' => trans('directory.keywords')]; $rules = ['is_root' => 'required', 'name' => 'required|between:2,50|unique:categories,name,' . $id, 'path' => 'required|between:2,50|unique:categories,path,' . $id, 'description' => 'between:5,1000', 'keywords' => 'between:5,255']; $is_root = Input::get('is_root'); if ('no' == $is_root) { $nice_input_names['parent_id'] = trans('directory.parent'); if ($id == Input::get('parent_id')) { //return Redirect::route('category.edit', [$id])->with('error', trans('directory.same_category_choosen'))->withInput(); } } $validator = Validator::make(Input::all(), $rules, [], $nice_input_names); if ($validator->fails()) { return Redirect::route('category.edit', [$id])->withErrors($validator)->withInput(); } $status = Acl::isSuperAdmin() ? 1 : 0; $category->update(['status' => $status, 'name' => e(Input::get('name')), 'slug' => $path, 'path' => $path, 'description' => e(Input::get('description')), 'keywords' => e(Input::get('keywords'))]); try { if ('yes' == $is_root) { $category->makeRoot(); } if ('no' == $is_root) { $parent = Category::find(e(Input::get('parent_id'))); if ($id != Input::get('parent_id') && !$parent->isDescendantOf($category)) { $category->makeChildOf($parent); } } return Redirect::route('category.edit', [$id])->with('success', Lang::get('directory.category_updated', ['category' => $category->name])); } catch (Exception $ex) { dd($ex->getMessage()); return Redirect::route('category.edit', [$id])->withErrors($ex->getMessage())->withInput(); } }