GithubHelp home page GithubHelp logo

Comments (6)

walidbagh avatar walidbagh commented on May 19, 2024 1

Hey, @saqueib,
This is an awsome package, unfortunately i'm having this same issue, which is that calling
Auth::user()->givePoint(new GroupCommentCreated($comment));
results in
payee() method must return a model which will get the points..

The problem is when calling the method givePoint on a user class ( in my case Auth::user() ), it still tries to find the payee using the payee() function of the PointType Class , which is redundant in my opinion.

The expected behaviour in this situation is to give the points to the user on which the givePoint methond has been executed.

from laravel-gamify.

saqueib avatar saqueib commented on May 19, 2024

Share your ProjectCreated point class

from laravel-gamify.

zhpeh avatar zhpeh commented on May 19, 2024

Thanks for your prompt reply. My ProjectCreated class is as follows:

<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class ProjectCreated extends PointType
{
    /**
     * Number of points
     *
     * @var int
     */
    public $points = 20;

    /**
     * Point constructor
     *
     * @param $subject
     */
    public function __construct($subject)
    {
        $this->subject = $subject;
    }

    /**
     * User who will be receive points
     *
     * @return mixed
     */
    public function payee()
    {
        return $this->getSubject()->user;
    }

}

from laravel-gamify.

saqueib avatar saqueib commented on May 19, 2024

make sure Project model has a belongsTo on the User model. and try this at last

// Creates the project
$project = Project::create($attributes);

// Rewards points
givePoint(new ProjectCreated($project->fresh()));

from laravel-gamify.

zhpeh avatar zhpeh commented on May 19, 2024

Hey @saqueib,

Thanks for your reply. I have figured out the issue with my case which is that my Project model has a method called owner() instead of user(). By changing from owner() to user(), it works now.

For the benefit of others who might be facing the same error message, ensure that your model has the user() method as such:

Project Model:

public function user()
{
     return $this->belongsTo(User::class);
}

from laravel-gamify.

jadamec avatar jadamec commented on May 19, 2024

The expected behaviour in this situation is to give the points to the user on which the givePoint methond has been executed.

I must agreee with you @walidbagh . How can I achieve that, please (even by writing a custom PointType class). Thanks!
#42

from laravel-gamify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.