Beispiel #1
0
 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');
 }