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(); } }
public function editHandle() { $domain = Domain::find(e(Input::get('id'))); $valid_domain = function ($domain_name) { return preg_match("/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*\$/i", $domain_name) && preg_match("/^.{1,253}\$/", $domain_name) && preg_match("/^[^\\.]{1,63}(\\.[^\\.]{1,63})*\$/", $domain_name); //length of each label }; $format_url = rtrim(str_replace(['http://', 'https://'], '', e(Input::get('url'))), '/'); if (!$valid_domain($format_url)) { return Redirect::back()->with('error', trans('directory.invalid_url'))->withInput(); } $nice_input_names = ['category_id' => trans('directory.select_category'), 'name' => trans('directory.name'), 'url' => trans('directory.url'), 'format_url' => trans('directory.url'), 'description' => trans('directory.description'), 'keywords' => trans('directory.keywords')]; $rules = ['category_id' => 'not_in:"0"', 'name' => 'required|between:6,260', 'url' => 'required|between:6,100|unique:domains,url,' . e(Input::get('id')), 'description' => 'required|between:200,1000', 'keywords' => 'between:5,255']; if (!Auth::check()) { $nice_input_names['g-recaptcha-response'] = 'captcha'; $rules['g-recaptcha-response'] = 'required|recaptcha'; } $validator = Validator::make(Input::all(), $rules, [], $nice_input_names); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $coma_replace = function ($string) { return str_replace(',', ', ', $string); }; $domain->category_id = (int) e(Input::get('category_id')); $domain->status = 0; $domain->name = $coma_replace(e(Input::get('name'))); $domain->url = 'http://' . $format_url; $domain->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.')); $domain->keywords = $coma_replace(e(Input::get('keywords'))); if ($domain->save()) { return Redirect::to(Domain::seoURL($domain->id))->with('success', trans('directory.domain_updated')); } return Redirect::back()->with('error', trans('directory.domain_edit_error')); }