芝麻web文件管理V1.00
编辑当前文件:/home/sditechnicalteam/public_html/app/Http/Controllers/ProductSubCategoryController.php
categoryID = $request->catID; $this->subcategories = ProductSubCategory::all(); $this->categories = ProductCategory::all(); return view('products.sub-category.create', $this->data); } /** * @param StoreProductSubCategory $request * @return array * @throws \Froiden\RestAPI\Exceptions\RelatedResourceNotFoundException */ public function store(StoreProductSubCategory $request) { $category = new ProductSubCategory(); $category->category_id = $request->category_id; $category->category_name = $request->category_name; $category->save(); $categoryData = ProductCategory::get(); $subCategoryData = ProductSubCategory::get(); $category = ''; $subCategory = ''; foreach ($subCategoryData as $item) { $subCategory .= '
'.ucwords($item->category_name).'
'; } foreach ($categoryData as $data) { $category .= '
'.ucwords($data->category_name).'
'; } return Reply::successWithData(__('messages.categoryAdded'), ['data' => $category, 'subCategoryData' => $subCategory]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $category = ProductSubCategory::findOrFail($id); $category->category_id = $request->category_id ? $request->category_id : $category->category_id; $category->category_name = $request->category_name ? strip_tags($request->category_name) : $category->category_name; $category->save(); $subCategoryOptions = $this->categoryDropdown($category->category_id); $categoryOptions = $this->subCategoryDropdown($category->id); return Reply::successWithData(__('messages.updatedSuccessfully'), ['sub_categories' => $subCategoryOptions, 'categories' => $categoryOptions]); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { ProductSubCategory::destroy($id); return Reply::success(__('messages.categoryDeleted')); } public function categoryDropdown($selectId = null) { /* Category Dropdown */ $categoryData = ProductCategory::get(); $categoryOptions = '
--
'; foreach ($categoryData as $item) { $selected = ''; if (!is_null($selectId) && $item->id == $selectId) { $selected = 'selected'; } $categoryOptions .= '
' . $item->category_name . '
'; } return $categoryOptions; } public function subCategoryDropdown($selectId) { /* Sub-Category Dropdown */ $subCategoryData = ProductSubCategory::get(); $subCategoryOptions = '
--
'; foreach ($subCategoryData as $item) { $selected = ''; if ($item->id == $selectId) { $selected = 'selected'; } $subCategoryOptions .= '
' . $item->category_name . '
'; } return $subCategoryOptions; } public function getSubCategories($id) { $sub_categories = ($id == 'null') ? ProductSubCategory::get() : ProductSubCategory::where('category_id', $id)->get(); return Reply::dataOnly(['status' => 'success', 'data' => $sub_categories]); } }