How can I convert stdClass to Array to update my DB in Laravel?
$currentSubscriptionTransaction = new stdClass();
$subscription_transaction_to_update = DB::table('subscription_transactions')->where('id', $currentSubscriptionTransaction->id)->first();
if (!is_null($subscription_transaction_to_update)) {
DB::table('subscription_transactions')->where('id', $currentSubscriptionTransaction->id)->update(
($currentSubscriptionTransaction)
);
}
I tried
array($currentSubscriptionTransaction)
but it didn’t work.
2
Answers
Try this:
A cleaner way of doing the same by using
Eloquent Model
humm…
Maybe, you should better use some
helper functions
likecollect()
andtoArray()
?see https://readouble.com/laravel/5.7/en/helpers.html if your laravel version is 5.7
Laravel supply some useful methods or tips belong with your laravel app version.
For example if you use a DB table , this framework has model.php like
SubscriptionTransactions
underModels/
So,Can you try these code under following?