/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $rules = array('category' => 'required|Integer', 'condition' => 'required|Integer', 'name' => 'required', 'description' => 'required', 'donor' => 'required|Integer', 'orignal_price' => 'required|Numeric', 'price' => 'required|Numeric', 'image' => 'required', 'attributes' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return $this->response(array('statusCode' => 400, 'statusDescription' => 'Bad Request', 'errors' => $validator->messages()->toJson())); } else { $iGetInstitute = Donor::where('user_id', Input::get('donor'))->first(); $product = Product::find($id)->update(array('products_price' => Input::get('price'), 'products_orginal_price' => Input::get('orignal_price'), 'brand' => Input::get('brand', NULL), 'products_status' => Input::get('products_status', 1), 'products_donar' => Input::get('donor'), 'condition' => Input::get('condition'), 'products_image' => Input::get('image'), 'gender' => Input::get('gender'), 'age_range' => Input::get('age_range'), 'collections_id' => Input::get('collections_id'), 'seasons_id' => Input::get('seasons_id'), 'types_id' => Input::get('types_id'), 'freshly_faved' => Input::get('freshly_faved'), 'institution_id' => $iGetInstitute->institution_id)); // $product->save(); $category = Categories::find(Input::get('category')); $product = Product::find($id); //$product->productCategory()->save($category); Product::find($id)->productCategory()->detach(); //updateExistingPivot($category->categories_id, array("categories_id"=>$category->categories_id),false); $product->productCategory()->save($category); if (Input::has('tags')) { Product::find($id)->productTags()->detach(); $product = Product::find($id); $inptags = Input::get("tags"); $tags = explode(",", $inptags); foreach ($tags as $key => $value) { $ctag = Tags::find($value); if ($ctag) { $product->productTags()->save($ctag); } } } $attributes = json_decode(Input::get("attributes"), TRUE); //$attribs = array(); ProductsAttributes::where("products_id", $id)->delete(); foreach ($attributes as $key => $value) { $opt_values = explode(",", $value); foreach ($opt_values as $optval) { //echo $key." ".$optval."<br/>"; $attribute = new ProductsAttributes(array('options_id' => $key, 'options_values_id' => $optval)); $product->productsAttributes()->save($attribute); } } $description = ProductsDescription::find($id)->update(array("products_name" => Input::get("name"), "products_description" => Input::get("description"))); //$product->productsDescription()->save($description); return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success')); } }
public function getGetEligibleDonors($bloodGroupId) { return Response::json(array('donors' => Donor::where('blood_group_id', '=', $bloodGroupId)->get())); }