OK it may be because it's late and it's been a long day but I'm having a real brain snap about this.
I'm updating some legacy code and it's (going to be) using Eloquent.
The code I'm updating at the moment is very procedural and function based and the refactoring is going slowly.
The user completes a task and earns some points
so I grab myself the user
$user = User::find($id)
work out how many point they deserve and it's come time where I have to add a reward to the users account.
So naturally my first though is
$user->addReward($reward)
all good until I go to the User model and have a complete brain spasm regarding how to go about it.
in the User Model and I'm sitting there staring at it working out how I'm supposed to do this
public function addReward($reward)
{
\\ new points = points + reward
$this->points =+ $reward
}
Then I'm doubting myself as to whether this is going to be referencing the right model and updating the correct user and then it's all downhill from there.
It's simple enough to pass through the userid and make sure but for whatever reason it doesn't feel right.. I've already grabbed the user now all I need to do is update their points..
shakes head I think I should just go to bed and try it again when I'm awake..