public function savePrice(Request $request) { $price = new Price(); $price->product = $request->input('product'); $price->price = $request->input('price'); $price->save(); return response()->json($price); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store($location_id, Request $request) { $location = Location::find($location_id); // create the new Location $price = new Price(); $price->type = $request->type; $price->price = $request->price; $price->price_date = $request->price_date; $price->location()->associate($location); $price->save(); return redirect()->action('LocationController@show', $price->location->id); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $rules = ['product' => 'required', 'description' => 'required|min:5|max:200', 'category' => 'required|digits:1', 'size' => 'required', 'image' => 'required|mimes:jpg,jpeg,png', 'price.*' => 'required|numeric']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { $errors = $validator->messages(); return back()->withInput()->withErrors($errors); } else { if ($request->file('image')->isValid()) { $image = $request->file('image'); # Image Object $filename = $image->getClientOriginalName(); # Image File Name $savedimg = $image->move(storage_path('app/posts'), $filename); # Saved Image Address # Create Post $product = new Product(); $product->name = $request->product; $product->des = $request->description; $product->cat_id = $request->category; $product->size = $request->size; $product->weight = $request->weight; $product->pic = $filename; $product->active = (bool) $request->active; # Redirect on Success if ($product->save()) { foreach ($product->cat->units as $unit) { $price = new Price(); $price->product_id = $product->id; $price->unit_id = $unit->id; $price->price = $request->price[$unit->id]; $price->save(); } return redirect()->route('product.create')->with('success', 'محصول با موفقیت ثبت شد.'); } } } return back()->withInput()->with('fail', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.'); }
private function syncPrices($id, $prices) { Price::where('event_id', '=', $id)->delete(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); foreach ($prices as $price) { $p = new Price(); $p->event_id = $id; $p->name = $price->priceName; $p->amount = $price->amount; $p->save(); } DB::statement('SET FOREIGN_KEY_CHECKS=1;'); }
public function postPrice(Request $request) { array_forget($request, "_token"); $all_request = $request->all(); $price = new Price(); foreach ($all_request as $key => $value) { $price->{$key} = $value; } $price->save(); $prices = Price::all(); if ($request->ajax()) { if ($prices) { foreach ($prices as $price) { echo "\n <tr>\n <td>{$price->id}</td>\n <td>{$price->name}</td>\n\n <td>{$price->description}</td>\n <td>{$price->created_at}</td>\n <td>{$price->updated_at}</td>\n <td></td>\n <td></td>\n </tr>\n "; } } exit; } return View("settings.price", ['prices' => $prices, 'papers' => Paper::all(), 'jobs' => Job::all(), 'title' => 'Job Price Setting']); }