public function store(Request $request) { ///validate data if it is in databse or not $data_to_val = $request->only('product_codes'); $rule = AuctionController::getRule($request); $user = JWTAuth::parseToken()->authenticate(); ///if login $validate = Validator::make($data_to_val, $rule); if ($user->role != 1) { return response()->json(['message', 'invalid Role']); } if ($validate->fails()) { return response()->json($validate->errors()->all()); } ///open new auction $auction = new Auction(); ////add finished time this is added by 1 hr $auction->finished_at = time() + 3600; $auction->buyer()->associate($user); $auction->save(); $products = []; $product_codes = $request->get('product_codes'); foreach ($product_codes as $key => $val) { $product = Product::where(['product_code' => $val])->get()->first(); $products[$key] = $product; } $auction->products()->saveMany($products); if ($auction->products->count() >= 1) { /////Generating Defualt Bid foreach ($product_codes as $val) { $product = Product::where(['product_code' => $val])->get()->first(); $product_descriptions = $product->product_descriptions; $lowest_price_description = ProductController::findLowestPriceProductDescription($product_descriptions); $bid = new Bid(['price' => $lowest_price_description->price]); $bid->seller()->associate($lowest_price_description->seller); $bid->auction()->associate($auction); $bid->save(); $bid->products()->saveMany([$product]); } //// if ($auction->bids->count() >= 1) { $auction->status = 0; //opening $auction->save(); return response()->json(['message', 'success']); } } return response()->json(['message', 'error occurred']); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($id, Request $request) { $validation = $this->validator($request->all()); $bids = Art::findOrFail($id)->bids()->get(); $lower = false; foreach ($bids as $bid) { //check if bid is higher than all other bids on this item if ($bid->price >= $request->input('amount')) { $lower = true; } } //if bid isn't higher, run exception if ($lower) { return redirect()->back()->withErrors(['er is reeds hoger geboden op deze veiling']); } else { //else make bid $bid = new Bid(); $bid->user_id = Auth::user()->id; $bid->art_id = $id; $bid->price = $request->input('amount'); $bid->save(); return redirect()->back()->withSuccess('succesvol geboden!'); } }
public function addBid() { if (\Request::ajax()) { $bid = new Bid(); $bid->project_id = Input::get('project_id'); $bid->user_id = Input::get('user_id'); $bid->amount = Input::get('offer'); $bid->days = Input::get('days'); $bid->description = Input::get('description'); $bid->hours = Input::get('hours'); $bid->amount_per_hour = Input::get('hoursmoney'); $bid->description = Input::get('description'); $bid->save(); $user = User::find($bid->user_id); echo json_encode(array('bid' => $bid, 'user' => $user)); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function bid(Request $request) { $this->validate($request, ['id' => 'required', 'bid' => 'required']); $data = $request->all(); $bid = new App\Bid(); $bid->user_id = Auth::user()->id; $bid->auction_id = $data['id']; $bid->price = $data['bid']; $bid->save(); $locale = App::getLocale(); $highestbid = App\Bid::where('auction_id', $bid->auction_id)->orderBy('price', 'DESC')->first(); $auction = Auction::where('id', $bid->auction_id)->first(); if ($highestbid->price > $auction->current_price) { $auction->current_price = $highestbid->price; $auction->save(); } $bids = Auction::join('bids', 'bids.auction_id', '=', 'auctions.id')->where('bids.user_id', Auth::User()->id)->translatedIn($locale)->get(); $newest = Auction::translatedIn($locale)->where('end_date', '>=', Carbon::now())->orderBy('created_at', 'DESC')->first(); return view('my_bids.index', array('auctions' => $bids, 'newest' => $newest)); }
public function bid(Request $request) { $this->validate($request, ['bid' => 'required|numeric']); $bid = Art::find($request->art)->highest(); if ($bid < $request->bid) { $input = Bid::where('user_id', Auth::user()->id)->where('art_id', $request->art)->first(); if (empty($input)) { $input = new Bid(); $input->art_id = $request->art; $input->user_id = Auth::user()->id; } $input->bid = $request->bid; $input->save(); return redirect()->back()->withSuccess(trans('succes.bid', ['bid' => $request->bid])); } else { return redirect()->back()->withErrors(['U moet hoger bieden, er is al €' . $bid . ' geboden']); } }
public function postBid($property_id, Request $request) { $user = $request->user(); //echo $request->bid_amount; //exit(); $bid = new Bid(); $bid->user_id = $user->id; $bid->property_id = $property_id; $bid->bid_amount = $request->bid_amount; $bid->save(); return redirect('properties/bid/' . $property_id); }
function addBid($price, $seller, $auction, $bundle) { $data = ['price' => $price]; $bid = new Bid($data); $bid->seller()->associate($seller); $bid->auction()->associate($auction); $bid->save(); $bid->products()->saveMany($bundle); }