/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function sizeadd(Request $request) { $cont = count($request->all()) - 3; $count = $cont / 4; // Validation // $validation = Validator::make($request->all(), ['name' => 'required|max:15', 'stock' => 'required|numeric']); $cur_clean = preg_replace('/\\./', '', $request->input('price')); $kg = preg_replace('/\\,/', '.', $request->input('weight')); $gram = $kg * 1000; // Check if it fails // if ($validation->fails()) { return redirect()->back()->withInput()->with('errors_var', $validation->errors()); } $size = new ProductSize(); $author = Auth::user()->id; if ($count > 1) { for ($i = 2; $i <= $count; $i++) { $sizes = $i; $sizes = new ProductSize(); $id_urut = $i; $name_post = "ID" . $i . "_name"; $name = $request->input($name_post); $stock_post = "ID" . $i . "_stock"; $stock = $request->input($stock_post); $s = $name . $i; $price_post = "ID" . $i . "_price"; $price = $request->input($price_post); $weight_post = "ID" . $i . "_weight"; $weight = $request->input($weight_post); $cc_v = preg_replace('/\\./', '', $price); $ready_price = $cc_v; $kg_v = preg_replace('/\\,/', '.', $weight); $gram_v = $kg_v * 1000; $ready_gram = $gram_v; // save size data into database // $sizes->name = $name; $sizes->id_products = $request->input('id_product'); $sizes->id_variants = $request->input('id_variant'); $sizes->add_price = $ready_price; $sizes->stock = $stock; $sizes->add_weight = $ready_gram; $sizes->save(); } } $seo = $request->input('name'); $seotitle = SeoHelper::seotitle($seo); // save size data into database // $size->name = $request->input('name'); $size->id_products = $request->input('id_product'); $size->id_variants = $request->input('id_variant'); $size->stock = $request->input('stock'); $size->add_price = $cur_clean; $size->add_weight = $gram; $size->save(); Alert::success('Success Create Sizes!')->persistent("Close"); return redirect('dropmin/product/variant/edit/' . $request->input('id_product') . '/' . $request->input('id_variant'))->with('message', 'You just create size!'); }
private function saveSize($data, $id = null) { if ($id) { $size = ProductSize::find($id); } else { $size = new ProductSize(); } $size->size = $data['size']; $size->price = $data['price']; $size->product_id = $data['product_id']; $size->save(); return 0; }