siewlon6093
4 months ago
1070
6
Laravel

Error: Call to a member function increment() on null

Posted 4 months ago by siewlon6093
    public function test_a_user_earns_points_when_they_create()
    {
       $like = factory('App\Models\Like')->create();

       $this->assertEquals(10, $like->creator->reputation);
    }

Testphp

   protected static function boot()
    {
        parent::boot();

        static::created(function ($like){
            $like->creator->increment('reputation', 10);
        });
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

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

like.php

Please sign in or create an account to participate in this conversation.