Reputation: 1
I want to update my table webcart ,which has this particular column named "identifier" where all transaction id lies Now I want to update the status and reason columns for particular identifier I have tried this
$amount=$request->amount;
$status=$request->status;
$reason=$request->unmappedstatus;
$txnid=$request->txnid;
$device = webcart::findOrFail($txnid);
$device->update([
'amount' => $amount,'status'=>$status,'reason'=>$reason
]);
but its not working for obvious reasons ,can someone tell me how to do it and what argument I have to pass in findorfail??
Upvotes: 1
Views: 68
Reputation: 2317
Since findOrFail method usages primary key of your table you can do the same thing by using where condition just like below
txnid
is the field of your device table field
$amount=$request->amount;
$status=$request->status;
$reason=$request->unmappedstatus;
$txnid=$request->txnid;
$device = webcart::where('txnid',$txnid);
$device->update([
'amount' => $amount,'status'=>$status,'reason'=>$reason
]);
Upvotes: 1
Reputation: 1164
Try with model->save() method like this, it works for update and insert both.
$device = new webcart();
$device->id = $request->id;
$device->txnid = $request->txnid;
$device->amount = $request->amount;
$device->status = $request->status;
$device->unmappedstatus = $request->unmappedstatus;
$device->save();
Upvotes: 0