Created
May 6, 2020 09:54
-
-
Save chrisvasey/f7b383f720c1606358483c00d418e66d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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