public function buynow($id) { $auction = Auction::getAuctionWithBuyerForId($id); $buyer = Auth::user(); $owner = $auction->owner; $bidders = Bid::getBiddersWithId($id); $auction->buyer_id = $buyer->id; $auction->save(); // Email to owner Mail::raw('Your artwork ' . $auction->title . ' has been sold!', function ($message) use($owner) { $message->from(env('MAIL_FROM'), env('MAIL_NAME')); $message->to($owner->email)->subject('Someone bough your artwork.'); }); // Email to buyer Mail::raw('Confirmation for the artwork you bought: ' . $auction->title . '!', function ($message) use($buyer) { $message->from(env('MAIL_FROM'), env('MAIL_NAME')); $message->to($buyer->email)->subject('You bought an artwork.'); }); // Email to bidders foreach ($bidders as $bidder) { Mail::raw('Auction ended! Someone bought an artwork you bid on: ' . $auction->title . '!', function ($message) use($bidder) { $message->from(env('MAIL_FROM'), env('MAIL_NAME')); $message->to($bidder->user->email)->subject('Someone bought an artwork you bid on.'); }); } // return $auction; return Redirect::route('home'); }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->call(function () { Mail::raw('Hi Dries!', function ($message) { $message->from(env('MAIL_FROM'), env('MAIL_NAME')); $message->to('*****@*****.**')->subject('Test mail!'); }); })->daily(); $schedule->call(function () { $expiringAuctions = Auction::getExpiringAuctions(); foreach ($expiringAuctions as $auction) { $bidders = Bid::getBiddersWithId($auction->id); $highest = Bid::getHighestBidWithId($auction->id); $auction->buyer_id = $highest->id; $auction->save(); foreach ($bidders as $bidWithBidder) { $bidder = $bidWithBidder->user; if ($bidder->id = $highest->id) { Mail::raw('Auction ' . $auction->title . ' ended, you are the highest bidder!', function ($message) use($bidder) { $message->from(env('MAIL_FROM'), env('MAIL_NAME')); $message->to($bidder->email)->subject('You are the highest bidder.'); }); } else { Mail::raw('Auction ' . $auction->title . ' ended, you did not give the highest bid!', function ($message) use($bidder) { $message->from(env('MAIL_FROM'), env('MAIL_NAME')); $message->to($bidder->email)->subject("Auction ended, you didn't get it."); }); } } } })->daily(); }