# How to Update User Wallet Points

**URL:** <https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228>\
**Category:** PHPRad Classic\
**Created:** [November 22, 2022, 5:34am UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228 "2022-11-22T05:34:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbtatiparthi](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@mbtatiparthi](https://forum.radsystems.io/u/mbtatiparthi)\
**Post date:** [November 22, 2022, 5:34am UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/1 "2022-11-22T05:34:32Z")

</div>

Hello Friends please help me to solve this problem…

Tables : users, wallet

users: id, name, points  
wallet: id, name, wlpoints, uid

Page Events Code: AfterAdd --:

$pupdate = $records[‘points’];  
DB::table(users)-\>WHARE(‘id’, $records[‘uid’])-\>update([‘wlpoints’, $pupdate]);

After Submitting Wallet Points it’s replaces old value with new value… But i need add old value with current value…

Ex: old wlpoints = 25, New Wallet Points= 5;

In my case ‘25’ replacing with ‘5’… 😔

I need newpoints to be 30 (25+5)

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 23, 2022, 11:38am UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/2 "2022-11-23T11:38:31Z")

</div>

you need to query your table to get the old point, then add the old point to the new point before updating the point.

---

<div class="post-metadata">

**Author:** ![mbtatiparthi](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@mbtatiparthi](https://forum.radsystems.io/u/mbtatiparthi)\
**Post date:** [November 23, 2022, 1:23pm UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/3 "2022-11-23T13:23:08Z")

</div>

Thank you for your support…  
Will this work

Tables : users, wallet

users: id, name, points  
wallet: id, name, wlpoints, uid

Page Events Code: AfterAdd --:

$pupdate = $records[‘points’];

$userwlpoints = DB::table(users)-\>WHERE(‘id’, $records[‘uid’])-\>get([‘wlpoints’,$records[‘uid’]]);

$totalpoints = $userwlpoints + $pupdate;

DB::table(users)-\>WHARE(‘id’, $records[‘uid’])-\>update([‘wlpoints’, $totalpoints]);

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 23, 2022, 11:41pm UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/4 "2022-11-23T23:41:30Z")

</div>

The below code should work.

```auto
$pupdate = $records['points'];
$userwlpoints = DB::table('users')->where('id', $records['uid'])->pluck('wlpoints');
$totalpoints = $userwlpoints + $pupdate;
DB::table('users')->where('id', $records['uid'])->update(['wlpoints' => $totalpoints]);

```

---

<div class="post-metadata">

**Author:** ![mbtatiparthi](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@mbtatiparthi](https://forum.radsystems.io/u/mbtatiparthi)\
**Post date:** [November 26, 2022, 3:54pm UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/5 "2022-11-26T15:54:49Z")

</div>

This returns error like this

ErrorException

Object of class Illuminate\Support\Collection could not be converted to number

[http://localhost:8050/wallet/store](http://localhost:8050/wallet/store)

This is my Code

```auto
    /**
     * After new record created
     * @param array $record // newly created record
     */
    private function afterAdd($record){
        //enter statement here
        
        $pupdate = $record['points'];
        $userwlpoints = DB::table('users')->where('id', $record['uid'])->pluck('wlpoints');
        $totalpoints = $userwlpoints + $pupdate;
        DB::table('users')->where('id', $record['uid'])->update(['wlpoints' => $totalpoints]);
    }
    

```

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 26, 2022, 10:26pm UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/6 "2022-11-26T22:26:16Z")

</div>

Use this instead.

```auto
$pupdate = $records['points'];
$userwlpoints = DB::table('users')->where('id', $records['uid'])->value('wlpoints');
$totalpoints = $userwlpoints + $pupdate;
DB::table('users')->where('id', $records['uid'])->update(['wlpoints' => $totalpoints]);

```

Please note that most of these functions are laravel functions and they are available in the laravel docs here [Database: Query Builder - Laravel - The PHP Framework For Web Artisans](https://laravel.com/docs/7.x/queries#main-content).

---

<div class="post-metadata">

**Author:** ![mbtatiparthi](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@mbtatiparthi](https://forum.radsystems.io/u/mbtatiparthi)\
**Post date:** [December 21, 2023, 3:38pm UTC](https://forum.radsystems.io/t/how-to-update-user-wallet-points/1228/7 "2023-12-21T15:38:11Z")

</div>

Hi… Thank you for the awesome tool…  
please help me to do onething…

in the Add Page… i want to check user have enough wallet credits to add one record to his list. if he has 0 or lessthan 100 i want to redirect to “wallet update page”(“userwallet.add”), how can i achive this… can you please help me…  
Once again thank you.
