/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $admin = Auth::User(); $data = $request->all(); $validator = Validator::make($data, ['sku' => 'required|unique:product,sku', 'category_id' => 'required', 'subcategory_id' => 'required', 'product_name' => 'required', 'brand_name' => 'required', 'product_price' => 'required', 'image1' => 'required|image']); if ($validator->fails()) { return redirect('/add_product_form')->withInput()->withErrors($validator); } else { $pro_id = ProductModel::create(['admin_id' => $admin->id, 'category_id' => $data['category_id'], 'subcategory_id' => $data['subcategory_id'], 'sku' => $data['sku'], 'product_name' => $data['product_name'], 'brand_name' => $data['brand_name'], 'product_quantity' => $data['product_quantity'], 'product_description' => $data['product_description'], 'product_price' => $data['product_price'], 'status' => 1]); //image one start here.......... if (Input::file('image1')) { $image = Input::file('image1'); $filename = time() . '.' . $image->getClientOriginalExtension(); $path = 'product_images/'; $request->file('image1')->move($path, $filename); $image_path = $path . $filename; } ProdcutImageModel::create(['product_id' => $pro_id->id, 'image_path' => $image_path, 'status' => 1]); //image one end heree............. //image two start heree............. if (Input::file('image2')) { $image = Input::file('image2'); $filename = time() . '.' . $image->getClientOriginalExtension(); $path = 'product_images/'; $request->file('image2')->move($path, $filename); $image_path = $path . $filename; } ProdcutImageModel::create(['product_id' => $pro_id->id, 'image_path' => $image_path, 'status' => 1]); //imagee two end here........ //imagee three start here........ if (Input::file('image3')) { $image = Input::file('image3'); $filename = time() . '.' . $image->getClientOriginalExtension(); $path = 'product_images/'; $request->file('image3')->move($path, $filename); $image_path = $path . $filename; } ProdcutImageModel::create(['product_id' => $pro_id->id, 'image_path' => $image_path, 'status' => 1]); //image three end here........ //image four end here........ if (Input::file('image4')) { $image = Input::file('image4'); $filename = time() . '.' . $image->getClientOriginalExtension(); $path = 'product_images/'; $request->file('image4')->move($path, $filename); $image_path = $path . $filename; } ProdcutImageModel::create(['product_id' => $pro_id->id, 'image_path' => $image_path, 'status' => 1]); //image four end here........ return redirect()->route('add_product_form')->with('message', 'status change successfully.....'); } }