lundi 12 novembre 2018

belongs to many relation in laravel view

I have 3 tables (course,teacher,user) that have relations

in Course Model:

public function teachers()
{
    return $this->belongsToMany(Teacher::class);
}

teacher Model:

public function user()
{
    return $this->belongsTo(User::class);
}

my courses table has columns:

id - teacher1_id - teacher2_id - .....

my teachers table has columns:

id - user_id - .....

my users table has columns:

id - name - .....    

now I want to show name of each course teachers using course variable.
how to do this in view?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire