Reputation: 1339
I have this code:
if(Auth::user())
{
Auth::user()->points = $request->points + 100;
Auth::user()->save();
}
Everytime user hits submit button in comment box, he should get +100 points, the problem is when I hit submit, comment is saved and points is saved. For example if I had 0 points or more no matter how many, after every comment it's still keeps showing that I have 100. It seems that I can add another 100 to existing points, it just change the value it self and not adding more points.
Upvotes: 0
Views: 43
Reputation: 5008
You should try assigning it this way:
Auth::user()->points += 100;
If I understood your case correctly.
Basically you might wanna make sure that the $request->points
has the correct value. Or simply increase the value the user holds.
Another way to try is:
Auth::user()->increment('points', 100);
More about that here
Upvotes: 2