FareedR
161
2
Guides

Can someone show me the correct way to fix this relationship

Posted 9 months ago by FareedR
// Database
users
id  |   name
1       John 

// Database
user_skills
user_id |   skill_id
1           1
1           2

//Database
skills
id  |   skill_name
1       Java
2       Laravel


// User.php
 public function hasUserSkill()
    {
        return $this->hasMany('App\UserSkill');
    }
// Skill.php
public function userSkill()
    {
        return $this->hasMany('App\UserSkill');
    }
//UserSkill.php
public function users()
    {
        return $this->belongsToMany('App\User');
    }

    public function skills()
    {
        return $this->hasMany('App\Skill');
    }

am I right ?

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

Reply to

Use Markdown with GitHub-flavored code blocks.