3 months ago

BadMethodCallException : Model function doesn't exist even though it is there

Posted 3 months ago by mirsahib

I have 5 table but i am currently concern with 2 table Tenant and Payment, Tenant table has one to many relation with Payment table (Tenant table is also belongs to House table)

class Tenant extends Model
    protected $fillable = ['name','nid','nid_img','phone','exp_rent','paid_rent',


    public function house()
        return $this->belongsTo(House::class);

    public function payments()
        return $this->hasMany(Payment::class);

Here is the seeder function

public function run()
        factory(App\House::class, 10)->create()->each(function ($house) {
            // Seed the relation with one address
            $tenant = factory(App\Tenant::class,5)->make();
            $mother = factory(App\MotherMeter::class)->make();
            $sub_meter = factory(App\SubMeter::class)->make();
            $payment = factory(App\Payment::class,5)->make();

I am getting this error even though the function payments exists in the Tenant model


  Method Illuminate\Database\Eloquent\Collection::payments does not exist.

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