/**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     if (!\Auth::check()) {
         return redirect()->to('/panel/login');
     }
     $category = ProductsCategory::find($id);
     $existCheck = ProductsCategory::checkExisting($category, $id);
     if ($existCheck['error']['code']) {
         return view('panel.errors.404', $existCheck['error']['data']);
     }
     $pageData = self::getPageData('Edit Category', 'panel/products/categories/' . $id, 'PUT');
     $pageData['category'] = $category;
     return view('panel.category-product-modify', $pageData);
 }
示例#2
0
 public static function editRecord($id, $data)
 {
     $category = ProductsCategory::find($id);
     $existChecker = ProductsCategory::checkExisting($category, $id);
     if ($existChecker['error']['code']) {
         return $existChecker['error']['data'];
     }
     $rules = $category->rules;
     $messages = $category->messages();
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->fails()) {
         return ['error' => ['type' => 'invalidData', 'responseMessages' => $validator], 'success' => 0];
     }
     $category->title = $data['title'];
     $category->parent_id = $data['parent'];
     $category->save();
     return ['error' => 0, 'success' => 'You edited category "' . $category->title . '" successfully'];
 }