/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $auctions = Auction::all();
     foreach ($auctions as $auction) {
         $enddate = new DateTime($auction->enddate);
         $now = new Datetime();
         if ($enddate < $now) {
             $highest_bid = $auction->highest_bid;
             $auction_id = $auction->id;
             $highest_bidder = User::whereHas('bids', function ($q) use($highest_bid, $auction_id) {
                 $q->where('amount', '=', $highest_bid)->where('auction_id', '=', $auction_id);
             })->first();
             if ($highest_bidder) {
                 $bidders = User::whereHas('bids', function ($q) use($highest_bid, $auction_id) {
                     $q->where('auction_id', $auction_id)->where('amount', '>', $highest_bid);
                 })->get();
                 foreach ($bidders as $bidder) {
                     $this->info($auction->title . ' was not sold to ' . $bidder->email);
                     Mail::send('mails.loser', ['user' => $bidder], function ($ms) use($bidder) {
                         $ms->to($bidder->email, $bidder->company)->subject('Too bad!');
                     });
                 }
                 Mail::send('mails.winner', ['user' => $highest_bidder], function ($ms) use($highest_bidder) {
                     $ms->to($highest_bidder->email, $highest_bidder->company)->subject('Congratulations!');
                 });
                 $this->info($auction->title . ' was sold to ' . $highest_bidder->company);
             } else {
                 $auction->active = false;
                 $auction->expired = true;
                 $auction->save();
                 $this->info($auction->title . ' is expired.');
             }
         }
     }
 }
 public function index()
 {
     $auctions = Auction::all();
     $data = ['auction' => $auctions[0]];
     $auctions[0]->products;
     $auctions[0]->bids;
     return response()->json($data);
 }
Beispiel #3
0
                    </li>
                @else
                <li><a href="#" data-toggle="modal" data-target="#LoginModal"><i class="login"></i>Вхід</a></li>
                <li><a href="{{action('AuctionsController@getRegister')}}"><i class="reg"></i>Реєстрація</a></li>
                @endif
            </ul>
        </div>
    </nav>
    </div>
</div>

<div id="auctions_counts">
    <div class="container">
    <div class="row">
        <?php 
$auction_count = \App\Auction::all();
?>
        <?php 
$auction_count2 = \App\Auction::where('status', '=', 7)->get();
?>
        <div class="col-xs-6 count">Отримано {{ $auction_count->count() }} заявок на сумму: <span>{{ number_format($auction_count->sum('starting_price'), 0, ',', ' ') }} грн</span></div>
        <div class="col-xs-6 count">Проведено {{ $auction_count2->count() }} торгів на сумму: <span>{{ number_format($auction_count2->sum('final_price'), 0, ',', ' ') }} грн</span></div>
    </div>
    </div>
</div>

@yield('content')

<footer id="main_footer">
    <div class="container">
        <div class="row">
 public function getArtworks(Request $request)
 {
     $art = $request->input('term');
     $artworks = Auction::all();
     $return_array = [];
     foreach ($artworks as $artwork) {
         if (strpos(Str::lower($artwork->title), $art) !== false) {
             $return_array[] = array('value' => $artwork->title, 'id' => $artwork->id);
         }
     }
     return response()->json($return_array);
 }