After add in page event issue

hi, I insert the following code in the events page to change the status ( another table ) of the “status” field: DB :: table ('cart') -> where ('id', 4) -> update (['status' =>' prova ']) ;.
If I insert it in before add the status is changed regularly, if I insert it in after add I get the following error: ErrorException
Undefined variable: record