public function store_values() { $rules = array('option_id' => 'required|Integer', 'option_value' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return $this->response(array('statusCode' => 400, 'statusDescription' => 'Bad Request', 'errors' => $validator->messages()->toJson())); } else { //ProductsOptions::create(array('products_options_name' => Input::get('option_name'))); $option_value = new ProductsOptionsValues(array('products_options_values_name' => Input::get('option_value'))); $option_value->save(); $option = ProductsOptions::find(Input::get('option_id')); if ($option) { //$option->productsOptionsValues()->attach($option_value); //this executes the insert-query ProductsOptions::find(Input::get('option_id'))->productsOptionsValues()->save($option_value); return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success')); } else { return $this->response(array('statusCode' => 400, 'statusDescription' => 'Not Found')); } } //$option_id //$option_value }
public function searching($term) { $condition = array("New" => 1, "Perfect" => 2, "Good" => 3, "Blemist" => 4); $cond_prod_ids = array(); $product_ids = array(); $pro_ids = array(); $brand_prod_ids = array(); $cat_prod_ids = array(); $tag_prod_ids = array(); //Search by product condition if (in_array($term, $condition)) { $cond_prod_ids = Product::where("condition", "=", $condition[$term])->lists('products_id'); } //Search by product attribute name $product_values_ids = ProductsOptionsValues::where('products_options_values_name', 'LIKE', '%' . $term . '%')->lists('products_options_values_id'); if ($product_values_ids) { $product_ids = DB::table('bn_products_attributes')->whereIn('options_values_id', $product_values_ids)->lists('products_id'); } //Search by product name or description $pro_ids = ProductsDescription::where('products_name', 'LIKE', '%' . $term . '%')->orWhere('products_description', 'LIKE', '%' . $term . '%')->lists('products_id'); //Search by product brand $brand_ids = Brands::where('brand_name', 'LIKE', '%' . $term . '%')->lists('brands_id'); if ($brand_ids) { $brand_prod_ids = Product::whereIn("brand", $brand_ids)->lists('products_id'); } //Search product by category $cat_ids = Categories::where('title', 'LIKE', '%' . $term . '%')->lists('categories_id'); if ($cat_ids) { $cat_prod_ids = DB::table('bn_products_to_categories')->whereIn('categories_id', $cat_ids)->lists('products_id'); } //Search product by tags $tag_ids = Tags::where('title', 'LIKE', '%' . $term . '%')->lists('tags_id'); if ($tag_ids) { $tag_prod_ids = DB::table('bn_products_to_tags')->whereIn('tags_id', $tag_ids)->lists('products_id'); } $result_prod_ids = array_merge($product_ids, $cond_prod_ids, $pro_ids, $brand_prod_ids, $cat_prod_ids, $tag_prod_ids); $products = Product::whereIn('products_id', $result_prod_ids)->where('products_status', '1')->paginate(15); //->get(); if ($products) { $products = $this->product_add_detail($products); return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success', 'products' => json_decode($products->toJson(), true))); } else { return $this->response(array('statusCode' => 400, 'statusDescription' => 'Not Found')); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { ProductsOptionsValues::where('products_options_values_id', '=', $id)->delete(); return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success', 'message' => "Product Option Value Deleted Successfully")); // }