/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($id) { //add auction to watchlist $watchlist = new Watchlist(); $watchlist->user_id = Auth::user()->id; $watchlist->art_id = $id; $watchlist->save(); return redirect()->back()->withSuccess('added to watchlist'); }
/** * 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)); }
public function addToWatchlist($id) { $watchlistcheck = Watchlist::where('FK_auction_id', '=', $id)->where('FK_user_id', '=', Auth::user()->id)->first(); $newestAuction = Auction::where('FK_status_id', '=', 1)->orWhere('FK_status_id', '=', 3)->orderBy('created_at', 'desc')->first(); if ($watchlistcheck == null) { $newWatchlist = new Watchlist(); $newWatchlist->FK_user_id = Auth::user()->id; $newWatchlist->FK_auction_id = $id; $newWatchlist->save(); $watchlist = Watchlist::where('FK_user_id', '=', Auth::user()->id)->get(); $success = 'You successfully added an auction to your watchlist!'; return view('watchlist')->with('watchlist', $watchlist)->with('newestAuction', $newestAuction)->with('success', $success); } else { $watchlist = Watchlist::where('FK_user_id', '=', Auth::user()->id)->get(); $warning = 'This auction was already added to your watchlist!'; return view('watchlist')->with('watchlist', $watchlist)->with('newestAuction', $newestAuction)->with('warning', $warning); } }