Volatil3
Volatil3

Reputation: 15008

Error in bulk updating of multiple columns

I am using Laravel 5.6. I am trying to update multiple users with corresponding values. Below is my code:

$cash_nov_updates[] = [
    'cash_to_be_paid_order_matched'    => $cash_to_be_paid_order_matched_user,
    'nov_to_be_given_order_matched'    => $nov_to_be_given_order_matched_user,
    'nov_to_be_obtained_order_matched' => $nov_to_be_obtained_order_matched_user,
];

CashNovOwnership::whereIn( 'user_id', $list_order_user_ids )
    ->update( $cash_nov_updates );

Upon running it is generating query like:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: update 'cash_nov_ownership' set '0' = 0, '1' = 168.09, '2' = 377.05, '3' = 561.43, '4' = 561.43, '5' = 561.43, '6' = 561.43, '7' = 561.43, '8' = 561.43, '9' = 651.94, '10' = 717.24, '11' = 717.24, '12' = 924.12, '13' = 1067.78, '14' = 1331.18, '15' = 1331.18, '16' =

Upvotes: 0

Views: 42

Answers (1)

Nagesh
Nagesh

Reputation: 437

Laravel update() requires single dimansional array, please modify

$cash_nov_updates = [
                    'cash_to_be_paid_order_matched'    => $cash_to_be_paid_order_matched_user,
                    'nov_to_be_given_order_matched'    => $nov_to_be_given_order_matched_user,
                    'nov_to_be_obtained_order_matched' => $nov_to_be_obtained_order_matched_user,
                ];

Upvotes: 1

Related Questions