Giter Club home page Giter Club logo

Comments (5)

saqueib avatar saqueib commented on June 18, 2024 1

It looks like you don't have user relation setup on Post model

class Post extends Model
    ...

   public function user() {
        return $this->belongsTo('App\User');
   }
}

please check and it should work

from laravel-gamify.

CyrilBlankaert avatar CyrilBlankaert commented on June 18, 2024

I've updated my code, but it doesn't work yet

           $get_content = $request->input('content');
           $user_id = Auth::user()->id;

           $post = $user->posts()->create(array(
               'content' => $get_content,
               'user_id' => $user_id
           ));

           givePoint(new PostCreated($post));

from laravel-gamify.

saqueib avatar saqueib commented on June 18, 2024

Please share your PostCreated point class

from laravel-gamify.

CyrilBlankaert avatar CyrilBlankaert commented on June 18, 2024

I didn't change the base of the PostCreated Class, as mentioned in the readme file.

<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class PostCreated 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;
    }
}

$this->getSubject()->user return "null" value

$this return :

PostCreated {#996 ▼ +points: 20 #payee: "user" #subject: Posts {#962 ▼ #table: "posts" #fillable: array:4 [▶] #connection: "mysql" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: true #attributes: array:5 [▶] #original: array:5 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #guarded: array:1 [▶] } }

from laravel-gamify.

CyrilBlankaert avatar CyrilBlankaert commented on June 18, 2024

It works, i already have a function with users but called "Users" and not "user"
Thanks for your help !

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.