You could simply make the default for status rejected and when a user selects one change that particular one to accepted. Or leave the status as null on all quotations and only update the selected one as accepted.
Sep 13, 2022
8
Level 2
Change all record content except one
Hi, I have one scenario in which multiple workshops send quotations to the user and the user can accept one quotation, Now I want to make a booking based on an accepted quotation by the user. when a user accept a quotation I want to change the status of that particular quotation to be accepted and for all other quotations I want to mark it as rejected. Hope you guys understand my question. I want a clean way to do that now what I am doing.
$acceptedQuote = AcceptedQuote::find($request->accepted_id);
$acceptedQuote->status = 'accepted';
$acceptedQuote->save();
$acceptedQuotes = AcceptedQuote::where('id','!=',$request->accepted_id)->where('quote_id',$request->quote_id)->get();
foreach($acceptedQuotes as $acceptedQuote ){
$acceptedQuote->status = 'rejected';
$acceptedQuote->save();
}
Level 102
Two queries should work
$acceptedQuote = AcceptedQuote::find($request->accepted_id);
$acceptedQuote->status = 'accepted';
$acceptedQuote->save();
$acceptedQuotes = AcceptedQuote::where('id','!=',$request->accepted_id)->where('quote_id',$request->quote_id)->update(['status' => 'rejected');
Please or to participate in this conversation.