0

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.

1
  • You already have your answer, but to comment on this code: probably $request->points has a value of 0 (or nothing at all, thus resulting in null which is equal to 0 if you're doing math), thus 0 + 100 = 100... Commented Jul 22, 2015 at 11:24

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah it's working right now! I will accept your answer after 10 minutes!
Great! as long as it helped you understand what was the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.