/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $rules = array('name' => 'required', 'description' => 'required', 'price' => 'required|integer|min:1000', 'category_id' => 'required', 'type_id' => 'required', 'address' => 'required');
     $input = Input::except('_token');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Redirect::action('ProductController@edit', $id)->withErrors($validator);
     } else {
         $input['price_id'] = CommonProduct::getPriceId($input['price']);
         CommonNormal::update($id, $input);
         return Redirect::action('ProductController@index')->with('message', 'Đã sửa');
     }
 }
 public function post()
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     //check user active
     $checkUser = User::find($input['user_id'])->status;
     if (isset($checkUser) && $checkUser == INACTIVE) {
         throw new Prototype\Exceptions\UserStatusErrorException();
     }
     // create product
     $inputSubmit = ['name' => $input['name'], 'user_id' => $input['user_id'], 'category_id' => $input['category_id'], 'type_id' => $input['type_id'], 'price_id' => CommonProduct::getPriceId($input['price']), 'price' => $input['price'], 'lat' => $input['lat'], 'long' => $input['long'], 'description' => $input['description'], 'avatar' => $input['avatar'], 'address' => $input['address'], 'city_id' => $input['city_id'], 'city' => Common::getModelField($input['city_id'], 'City', 'name'), 'position' => 1, 'status' => INACTIVE, 'start_time' => Carbon\Carbon::now()];
     $id = Product::create($inputSubmit)->id;
     // images product
     if (isset($input['image_url']) && count($input['image_url']) > 0) {
         foreach ($input['image_url'] as $key => $value) {
             $inputImage = array('product_id' => $id, 'image_url' => $value);
             ProductImage::create($inputImage);
         }
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId);
 }