afoysal
1 year ago

Relationship issue in Laravel

Posted 1 year ago by afoysal

I have 3 tables applicants,skills and applicant_skill. Here applicant_skill is the pivot table. applicant_skill table has 2 columns applicant_id, skill_id. One Applicant has many Skills. One Skill has many Applicants.

I wrote below function in model Applicants.php

public function applicantSkill()
    {
        return $this->belongsToMany(ApplicantSkill::class);
    }

I wrote below function in model Skills.php

public function applicantSkill()
{
    return $this->belongsTo(Applicant_skill::class);
}

I wrote below function in model ApplicantSkill.php

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

I am trying to fetch applicants in ApplicantController.php like below

$applicants = Applicants::with('applicant_skill', 'applicant_skill.skills')->paginate();

I am getting below error.

enter image description here

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