/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $locale = App::getLocale(); $newest = Auction::translatedIn($locale)->where('end_date', '>=', Carbon::now())->orderBy('created_at', 'DESC')->first(); $myBids = Auction::join('bids', 'bids.auction_id', '=', 'auctions.id')->where('bids.user_id', Auth::User()->id)->translatedIn($locale)->get(); /** * Return all acutions */ return view('my_bids.index', array('auctions' => $myBids, 'newest' => $newest)); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['id' => 'required']); $data = $request->all(); $existing = Watchlist::where('user_id', Auth::user()->id)->where('auction_id', $data['id'])->first(); if (!$existing) { $watchlist = new Watchlist(); $watchlist->user_id = Auth::user()->id; $watchlist->auction_id = $data['id']; $watchlist->save(); } $locale = App::getLocale(); $watchlists = Auction::join('watchlist', 'watchlist.auction_id', '=', 'auctions.id')->where('watchlist.user_id', Auth::User()->id)->translatedIn($locale)->get(); $newest = Auction::translatedIn($locale)->where('end_date', '>=', Carbon::now())->orderBy('created_at', 'DESC')->first(); return view('watchlist.index', array('auctions' => $watchlists, 'newest' => $newest)); }
/** * 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)); }