Hi, I have 2 tables employers and employers_jobs. employers have a column of id and name while employers_jobs have a column of idemployer_id and employers_job_title
the problem: the employers table returns null. I believe this called inverse relationship
here are some of my codes:
//Employer.php (model)
public function EmployersJobs(){
return $this->hasMany(EmployersJobs::class);
}
//EmployersJobs.php (model) this might be the culprit
public function Employer(){
return $this->belongsTo(Employer::class);
}
You need to pass your foreign key as the second parameter if the foreign key name is not exactly as "yourtablename_id"
//Employer.php (model)
public function EmployersJobs(){
return $this->hasMany(EmployersJobs::class,'employer_id');
}
//EmployersJobs.php (model) this might be the culprit
public function Employer(){
return $this->belongsTo(Employer::class,'id');
}