skip to Main Content

When updating my cart model, I run:

$cart->transaction_id= $result->salePaymentRequestResult->token;

$cart->save();

This does update my cart. But it with different value. Why is my model not being updated correctly?

I get no errors.
The cart does not get updated in the db correctly.
No errors. Behavior as normal.
Result of running this test to see if save succeeded was true.
This Laravel thread was no help
cart model:

3

Answers


  1. Since your question is lacking context, I’ll suggest isolating the statements and log the values. You can start by asking the following questions:

    1. What’s the value of $result->salePaymentRequestResult->token at that point of code?
    2. What happens when you assign a static string to $cart->transaction_id? For example: $cart->transaction_id = 'test_token';
    3. Is there any mutator defined for transaction_id attribute? Defining a Mutator
    4. Is there any observer defined for the model? Observers
    Login or Signup to reply.
  2. It’s possible that the issue is due to the $fillable attribute not including transaction_id. Laravel prevents mass assignment for fields that aren’t in the $fillable array, which could cause the value not to save properly.

    protected $fillable = ['transaction_id', /* other fields */];
    

    Sometimes cached data might show old values.

    php artisan cache:clear
    
    Login or Signup to reply.
  3. Because of the limited context, I think you should log the value of $result->salePaymentRequestResult->token to make sure it’s the correct data.

    Log::info('Token:', [$result->salePaymentRequestResult->token]);

    I think this should shed more light on your issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search