/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // Validation // $validation = Validator::make($request->all(), ['caption' => 'required|regex:/^[A-Za-z ]+$/', 'description' => 'required', 'userfile' => 'required|image|mimes:jpeg,png|min:1|max:5250']); // Check if it fails // if ($validation->fails()) { return redirect()->back()->withInput()->with('errors', $validation->errors()); } $product = new Product(); // upload the product // $image = $request->file('userfile'); $filename = time() . '.' . $image->getClientOriginalExtension(); $path = public_path('assets/products/' . $filename); $img = Image::make($image->getRealPath()); // resize the image to a width of 300 and constrain aspect ratio (auto height) $img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); }); $img->save($path); $seo = $request->input('caption'); $seotitle = SeoHelper::seotitle($seo); // save product data into database // $product->file = $filename; $product->caption = $request->input('caption'); $product->description = $seotitle; $product->save(); Alert::success('Success Create!')->persistent("Close"); return redirect('dropmin/product/list')->with('message', 'You just uploaded an image!'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $validation = Validator::make($request->all(), Category::rules($id), ['description' => 'required']); // Check if it fails // if ($validation->fails()) { return redirect()->back()->withInput()->with('errors', $validation->errors()); } if (!$request->input('publish')) { $publish = 0; } else { $publish = 1; } // Process valid data & go to success page // $category = Category::find($id); // replace old data with new data from the submitted form // $author = Auth::user()->id; $seo = $request->input('name'); $seotitle = SeoHelper::seotitle($seo); // save category data into database // $category->name = $request->input('name'); $category->name_seo = $seotitle; $category->id_user = $author; $category->description = $request->input('description'); $category->publish = $publish; $category->save(); Alert::success($request->input('name') . ' Saved!')->persistent("Close"); return redirect('dropmin/category/list')->with('message', 'You just updated an cateogry!'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // Validation // $validation = Validator::make($request->all(), ['userfile' => 'required|image|mimes:jpeg,png|min:1|max:8000']); // Check if it fails // if ($validation->fails()) { return redirect()->back()->withInput()->with('errors', $validation->errors()); } $url = $request->input('get'); $nm = $request->input('nm'); $id = $request->input('id'); $real_url = $request->input('get'); if ($url == 'category') { $url = 'categories'; } $author = Auth::user()->id; $pict = new Pict(); // upload the product // $image = $request->file('userfile'); $filename = time() . '.' . $image->getClientOriginalExtension(); $nm_name = 'nm_' . $filename; $xl_name = 'xl_' . $filename; $path = public_path('assets/' . $url . '/' . $filename); $img = Image::make($image->getRealPath()); // resize the image to a width of 300 and constrain aspect ratio (auto height) $img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); }); $img->save($path); //normal image *nm_ $nm_path = public_path('assets/' . $url . '/' . $nm_name); $nm_img = Image::make($image->getRealPath()); // resize the image to a width of 300 and constrain aspect ratio (auto height) $nm_img->resize(900, null, function ($constraint) { $constraint->aspectRatio(); }); $nm_img->save($nm_path); //big image *xl_ $xl_path = public_path('assets/' . $url . '/' . $xl_name); $xl_img = Image::make($image->getRealPath()); // resize the image to a width of 300 and constrain aspect ratio (auto height) $xl_img->resize(1020, null, function ($constraint) { $constraint->aspectRatio(); }); $xl_img->save($xl_path); $iddes = 'id_' . $url; $seo = $request->input('caption'); $seotitle = SeoHelper::seotitle($seo); // save pict data into database // $pict->pict = $filename; $pict->{$iddes} = $id; $pict->id_user = $author; $pict->save(); Alert::success('Success Create!' . $url)->persistent("Close"); return redirect('dropmin/' . $real_url . '/edit/' . $id . '')->with('message', 'You just uploaded an image!'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $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', $validation->errors()); } if ($request->input('publish') == "") { $publish = 0; } else { $publish = 1; } $author = Auth::user()->id; $size = ProductSize::find($id); $seo = $request->input('name'); $seotitle = SeoHelper::seotitle($seo); // save size data into database // $size->name = $request->input('name'); $size->add_price = $cur_clean; $size->add_weight = $gram; $size->stock = $request->input('stock'); $size->publish = $publish; $size->save(); Alert::success('Success Update ' . $request->input('name') . '!')->persistent("Close"); return redirect('dropmin/product/variant/edit/' . $request->input('id_product') . '/' . $request->input('id_variant'))->with('message', 'You just updated an size!'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // Validation // $validation = Validator::make($request->all(), ['name' => 'required|unique:category_subs|max:255', 'categories' => 'required', 'sub_categories' => 'required', 'description' => 'required', 'price' => 'required', 'weight' => 'required', 'keyword' => 'required']); $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', $validation->errors()); } if ($request->input('publish') == "") { $publish = 0; } else { $publish = 1; } $author = Auth::user()->id; $product = Product::find($id); $seo = $request->input('name'); $seotitle = SeoHelper::seotitle($seo); // save product data into database // $product->name = $request->input('name'); $product->name_seo = $seotitle; $product->id_categories = $request->input('categories'); $product->id_category_subs = $request->input('sub_categories'); $product->id_user = $author; $product->base_price = $cur_clean; $product->base_weight = $gram; $product->keyword = $request->input('keyword'); $product->description = $request->input('description'); $product->publish = $publish; $product->save(); Alert::success('Success Update ' . $request->input('name') . '!')->persistent("Close"); return redirect('dropmin/product/list')->with('message', 'You just updated an product!'); }