Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tayyabshahzad1's avatar

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();
		}

0 likes
8 replies
RayC's avatar

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.

1 like
tayyabshahzad1's avatar

@RayC Thanks for your reply, actually when data is in AcceptedQuote model at that time I have set the default status of every row which is pending. in parallel, I have created an API in which I am sending all pending data from AcceptedQuote model. Now the requirement is when the user accepts any quote rest all AcceptedQuote will not show in that API to achieve this I have written this solution but as I know this is not the best approach I wrote.

Sinnbeck's avatar
Sinnbeck
Best Answer
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');
Sinnbeck's avatar

I meant the answer that had the solution ;)

Please or to participate in this conversation.