rizky Zulkarnaen
rizky Zulkarnaen

Reputation: 53

RelationNotFoundException Laravel

I'm facing a problem, as to why the relation is not getting connected.

vendor.php

class Vendor extends Model
{
    public function internets()
    {
        return $this->hasMany('App\Internet');
    }
}

internets.php

class Internet extends Model
{
    protected $with=['vendor','coba'];
    public function vendor()
    {
        return $this->belongTo('App\Vendor');
    }
}

any one can help me?

Upvotes: 0

Views: 488

Answers (2)

Mohsin
Mohsin

Reputation: 75

Try something like this

In your vendor

 class Vendor extends Model
{
    protected $table = 'Vendor Table Name';
    protected $primarykey = 'Your Vendor Table primary Key';
    public function internets()
    {
        return $this->hasMany(App\Internet::class, 'relational key');
    }
}

And In your internet

class Internet extends Model
{
    protected $with=['vendor','coba'];
    protected $table = 'Internet Table Name';
    protected $primarykey = 'Internet table primary key';
    public function vendor()
    {
        return $this->belongsTo(App\Vendor::class, 'relation key');
    }
}

I hope this will solve your problem let me know if this do the trick

Upvotes: 0

Nahid Hasan
Nahid Hasan

Reputation: 707

it will be belongsTo

return $this->belongsTo('App\Vendor');

Upvotes: 2

Related Questions