Carosobin's avatar

Argument #1 ($point) must be of type

im facing issue with this new point package who can assit me please what am trying to do is give user point after they have succefully created a post https://github.com/ansezz/laravel-gamify

App\Models\User::achievePoint(): Argument #1 ($point) must be of type Ansezz\Gamify\Point, App\Models\Post given, called in C:\Users\ADEALA\Desktop\tribe-app\tribe\app\Http\Livewire\PostCreate.php on line 56


public function createPost()
    {
        if (auth()->check()) {
            $this->validate();
            $random =  str_pad(mt_rand(1,999999),6,'0',STR_PAD_LEFT);
            $post = Post::create([
                'user_id' => auth()->user()->id,
                'title' => $this->title,
                'category_id' => $this->category,
                'body' => $this->body,
                'post_number' => $random,
                'slug' => Str::slug($this->title) ?? null,
            ]);
                $users = auth()->user();
                $users->achievePoint( new PostApproved($post));
            

                $image = $this->photo->storeAs('posts', str::random(30));
                $post->image = $image;
                $post->save();
                session()->flash("message", "Featured image successfully uploaded");

                preg_match_all('/(?<=#)(\w+)/mi', $this->body, $matchedTags, PREG_SET_ORDER, 0);
                foreach ($matchedTags as $matchedTag) {
                    if (!$tag = Tag::where('name', $matchedTag[0])->first()) {
                        $tag = tag::create(['name' => $matchedTag[0]]);
                    }
                    $post->tags()->attach($tag->id);
                    $tag->addEnergy(1);
                }

                preg_match_all('/(?<=@)(\w+)/mi', $this->body, $matchedMentions, PREG_SET_ORDER, 0);
                foreach ($matchedMentions as $matchedMention) {
                    optional(User::where('username', $matchedMention[0])->first(), function ($user) {
                        // $user->notify(new MentionsNotify($user));
                    });
                 }


            // $users = auth()->user();
            // $users->increment('points', 10);

            session()->flash('success_message', 'Post was added successfully!');

            $this->reset();

            return redirect()->route('post.index');
        }

        abort(Response::HTTP_FORBIDDEN);
    }
0 likes
3 replies
MichalOravec's avatar

Have you ever read a documentation of that package?

Because when you have to pass a model to the method, you pass a number and opposite...

1 like

Please or to participate in this conversation.