made a check to see if a bid had already been placed reducing duplicates in the database
This commit is contained in:
@@ -169,18 +169,28 @@ class ContractController extends Controller
|
|||||||
$corporationId = $lookup->LookupCharacter($characterId);
|
$corporationId = $lookup->LookupCharacter($characterId);
|
||||||
$corporationName = $lookup->LookupCorporationName($corporationId);
|
$corporationName = $lookup->LookupCorporationName($corporationId);
|
||||||
|
|
||||||
//Create the model object to save data to
|
//Before saving a bid let's check to see if the user already placed a bid on the contract
|
||||||
$bid = new Bid;
|
$found = Bid::where([
|
||||||
$bid->contract_id = $request->contract_id;
|
'contract_id' => $request->contract_id,
|
||||||
$bid->bid_amount = $amount;
|
'character_id' => $characterId,
|
||||||
$bid->character_id = $characterId;
|
])->first();
|
||||||
$bid->character_name = $characterName;
|
|
||||||
$bid->corporation_id = $corporationId;
|
|
||||||
$bid->corporation_name = $corporationName;
|
|
||||||
$bid->save();
|
|
||||||
|
|
||||||
//Redirect to the correct page
|
if(isset($found->contract_id)) {
|
||||||
return redirect('/contracts/display/public')->with('success', 'Bid accepted.');
|
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
|
||||||
|
$bid = new Bid;
|
||||||
|
$bid->contract_id = $request->contract_id;
|
||||||
|
$bid->bid_amount = $amount;
|
||||||
|
$bid->character_id = $characterId;
|
||||||
|
$bid->character_name = $characterName;
|
||||||
|
$bid->corporation_id = $corporationId;
|
||||||
|
$bid->corporation_name = $corporationName;
|
||||||
|
$bid->save();
|
||||||
|
|
||||||
|
//Redirect to the correct page
|
||||||
|
return redirect('/contracts/display/all')->with('success', 'Bid accepted.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user