示例#1
0
 public function getCategory($id)
 {
     $category = ProductsCategory::find($id);
     if (!$category) {
         return redirect()->to('shop');
     }
     $pageData = self::getPageElements($category->title, $category->title, '', '', true, false, false, $category->mainParent()->id);
     $products = $category->products;
     $pageData['products'] = $products;
     $pageData['category'] = $category;
     return view('shop', $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'];
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (!Auth::check()) {
         return redirect()->to('panel/login');
     }
     $category = ProductsCategory::find($id);
     $childs = $category->childs;
     foreach ($childs as $child) {
         $child->delete();
     }
     $category->delete();
     return redirect()->back();
 }