Skip to content

Instantly share code, notes, and snippets.

@chrisvasey
Created May 6, 2020 09:54
Show Gist options
  • Save chrisvasey/f7b383f720c1606358483c00d418e66d to your computer and use it in GitHub Desktop.
Save chrisvasey/f7b383f720c1606358483c00d418e66d to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Bid;
use Redirect;
use Illuminate\Http\Request;
class BidController extends Controller
{
public function index(Request $request)
{
$bids = Bid::all()->sortBy('amount');
$highestBid = $bids->sortBy('max_amount')->last();
return view('auction', compact('bids', 'highestBid'));
}
public function add(Request $request)
{
//Get all higher bids
$highestBid = $bids->sortBy('max_amount')->last();
$bid = new Bid;
$bid->amount = $request->amount;
$bid->max_amount = $request->amount;
$bid->user_id = $request->user_id;
$bid->save();
return Redirect('/');
}
public function delete()
{
$bids = Bid::all();
foreach ($bids as $bid) {
$bid->delete();
}
return Redirect('/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment