Reputation: 172
I've problem with belongsToMany relation on Laravel.Firstly, I want to describe my table structe.There 3 different table has got on my database.Projects, Skills and ProjectSkills are my tables.There is a structure of my model.It's working perfectly when I tried to insert project with skills.However, it's not listing skills when I tried to get a single project.
ProjectController:
$Project = Projects::with('skills')->where('Projects.SefTitle','=',$ProjectSef)->first();
return View::make('Projects.view',array('Project'=>$Project));
Project(Model)
...
public function skills(){
return $this->belongsToMany('Skills','ProjectSkills','ProjectID','SkillID');
}
...
View:
@foreach($Project->Skills as $Skill)
{{$Skill->Title}} <br />
@endforeach
Database and Datasets:
Upvotes: 1
Views: 112
Reputation: 152860
For primary keys that differ from the default Laravel uses (which is just id
) make sure you define your primary key on every of your model classes:
class Projects extends Eloquent {
protected $primaryKey = 'ProjectID';
}
Upvotes: 1