/** * Run the database seeds. * * @return void */ public function run() { Bid::create(['item' => 1, 'offer' => 2, 'owner' => 1, 'buyer' => 2, 'date_completed' => Carbon::now(), 'success' => true]); Bid::create(['item' => 2, 'offer' => 3, 'owner' => 2, 'buyer' => 1, 'date_completed' => Carbon::now(), 'success' => false]); Bid::create(['item' => 3, 'offer' => 1, 'owner' => 1, 'buyer' => 1, 'date_completed' => NULL, 'success' => false]); Bid::create(['item' => 2, 'offer' => 1, 'owner' => 2, 'buyer' => 1, 'date_completed' => NULL, 'success' => false]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $this->validate($request, ['id' => 'required', 'item_id' => 'required', 'buyer' => 'required', 'current_bid' => 'required', 'bid_date' => 'required']); Bid::create($request->all()); Session::flash('flash_message', 'Bid successfully added!'); return redirect('bid'); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); $users = User::get()->lists('id')->all(); $products = Product::get()->lists('id')->all(); foreach (range(1, 30) as $index) { Bid::create(['amount' => $faker->randomNumber(), 'user_id' => $faker->randomElement($users), 'product_id' => $faker->randomElement($products)]); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('bids')->delete(); $auctions = Auction::get(); foreach ($auctions as $auction) { $random_user = User::orderByRaw("RAND()")->first(); if (rand(0, 5) == 0) { Bid::create(['user_id' => $random_user->id, 'auction_id' => $auction->id, 'price' => $auction->min_price + 999]); } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $id) { $this->validate($request, ['amount' => 'required']); $user_id = Auth::User()->id; $auction_id = $id; if ($this->auction->highest_bid < $request['amount']) { $this->auction->updateHighestBid($request['amount'], $auction_id); } if (!$this->bid->hasAlreadyBid($user_id, $auction_id)) { Bid::create(['user_id' => $user_id, 'auction_id' => $auction_id, 'amount' => $request['amount']]); } else { $bid = Bid::where(['user_id' => $user_id, 'auction_id' => $auction_id])->first(); $bid->amount = $request['amount']; $bid->save(); } return redirect('/auctions/' . $id); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $bid = new Bid(); $bid->create($request->all()); return response()->json($bid); }
public function buy($art_id) { // art $art = Auction::where('id', '=', $art_id)->first(); $art->active = false; $art->save(); //store bid // check if user already has a bid Bid::where('user_id', '=', Auth::user()->User->id)->delete(); // create bid $bid['auction_id'] = $art_id; $bid['user_id'] = Auth::user()->User->id; $bid['price'] = $art->price_buy; $bid['bought'] = true; Bid::create($bid); Mail::raw('Congrats, you bought the auction for ' . $art->title . 'for the price of ' . $art->price_buy, function ($message) use($auth_user) { $message->to($auth_user->login->email)->subject('Congrats, you bought the auction'); $message->from('*****@*****.**'); }); // other bidders damn it mail $count = Bid::where('auction_id', '=', $art_id)->count(); $skip = 1; $limit = $count - $skip; // the limit $otherbids = Bid::where('auction_id', '=', $art_id)->orderBy('price', 'desc')->skip($skip)->take($limit)->get(); foreach ($otherbids as $key => $bid) { $user = User::where('id', '=', $bid->user_id)->first(); $emaillose = $user->login->email; Mail::raw('The auction ended, you lost the auction ' . $art->title, function ($message) use($emaillose) { $message->to($emaillose)->subject('The auction ended, you lost the auction '); $message->from('*****@*****.**'); }); } return view('congrats', compact('art')); }