made a check to see if a bid had already been placed reducing duplicates in the database

This commit is contained in:
2019-04-29 01:45:36 -05:00
parent 61b0e2f6dc
commit 2382d153e7

View File

@@ -169,6 +169,15 @@ class ContractController extends Controller
$corporationId = $lookup->LookupCharacter($characterId); $corporationId = $lookup->LookupCharacter($characterId);
$corporationName = $lookup->LookupCorporationName($corporationId); $corporationName = $lookup->LookupCorporationName($corporationId);
//Before saving a bid let's check to see if the user already placed a bid on the contract
$found = Bid::where([
'contract_id' => $request->contract_id,
'character_id' => $characterId,
])->first();
if(isset($found->contract_id)) {
return redirect('/contracts/display/all')->with('error', 'You have already placed a bid for this contract. Please modify the existing bid.');
} else {
//Create the model object to save data to //Create the model object to save data to
$bid = new Bid; $bid = new Bid;
$bid->contract_id = $request->contract_id; $bid->contract_id = $request->contract_id;
@@ -180,7 +189,8 @@ class ContractController extends Controller
$bid->save(); $bid->save();
//Redirect to the correct page //Redirect to the correct page
return redirect('/contracts/display/public')->with('success', 'Bid accepted.'); return redirect('/contracts/display/all')->with('success', 'Bid accepted.');
}
} }
/** /**