qcod / laravel-gamify

Gamify your Laravel app with Reputation Points & Achievements Badges support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Work with the specific payee (not subject's user)

jadamec opened this issue · comments

$post = auth()->user()->posts()->create($request->all()); // id: 1
$user = User::find(2); // id: 2

Why this method adds points to the user with the id: 1, and not on which it is pointing? What's the reason of the $user, then?
$user->givePoint(new PostCreated($post));

From what I can tell the givePoint helper function (helpers.php) can set the appropriate model, but the problem is once you get into the givePoint function from HasReputations.php where it finally calls to attach to the payee() things are lost. Been scratching my head on this for a bit today trying to figure it out as not all my models will have a direct user() relationship, most are through many to many.

In my project, I figured it out by passing a $user to these functions, ignoring payee() completely. Works like a charm!

Would be nice to get a more elegant solution put in as a PR though to make it work as expected!

I just added a pull request for how I did it. #43