From 7ac9c1dcd49483b795a1462bf2cd7d19199894ed Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Mon, 29 Apr 2019 01:50:21 -0500 Subject: [PATCH] all contracts --- app/Http/Controllers/ContractController.php | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ContractController.php b/app/Http/Controllers/ContractController.php index 7c81fcf9d..5b191cdd9 100644 --- a/app/Http/Controllers/ContractController.php +++ b/app/Http/Controllers/ContractController.php @@ -39,17 +39,30 @@ class ContractController extends Controller * */ public function displayContracts() { - //Caluclate today's date to know which contracts to display + //Calculate today's date to know which contracts to display $today = Carbon::now(); - //Declare array variables + //Declare our array variables $bids = array(); - $data = array(); $contracts = array(); + $i = 0; - $contracts = Contract::where(['end_date', '>=', $today])->get(); + //Fetch all of the current contracts from the database + $contractsTemp = Contract::where('end_date', '>=', $today)->get()->toArray(); - return view('contracts.allcontracts'); + //Count the number of bids, and add them to the arrays + for($i = 0; $i < sizeof($contractsTemp); $i++) { + $tempCount = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->count('contract_id'); + $bids = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->get()->toArray(); + + //Assemble the finaly array + $contracts[$i] = $contractsTemp[$i]; + $contracts[$i]['bid_count'] = $tempCount; + $contracts[$i]['bids'] = $bids; + } + + //Call for the view to be displayed + return view('contracts.allcontracts')->with('contracts', $contracts); } /**