我有三个数据库表.
CREATE TABLE `tblproject` ( `ProjectID` int(11) NOT NULL, `ProjectStatusID` varchar(30) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `tblprojectSkills` ( `ProjectSkillID` int(11) NOT NULL, `ProjectID` int NOT NULL, `SkillID` int NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `tblSkills` ( `SkillID` int(11) NOT NULL, `Skill` varchar(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
在上表中.SkillID
在相关tblSkills
和tblprojectSkills
.
ProjectID
在相关Project
和projectSkills
表
class Project_Model extends Model { protected $table = "tblproject"; protected $primaryKey = "ProjectID"; public $timestamps = false; public function ProjectSkills() { return $this->hasMany('\App\Models\ProjectSkill_Model', 'ProjectID'); } } class ProjectSkill_Model extends Model { protected $table = "tblprojectskill"; protected $primaryKey = "ProjectSkillID"; public $timestamps = false; } class Skill_Model extends Model { protected $table = "tblskill"; protected $primaryKey = "SkillID"; public $timestamps = false; }
\App\Models\Project\Project_Model ::with('ProjectSkills') ->where('ProjectID', '=', $ProjectID)->first();
我可以获得技能ID,但是,我如何从技能表中获得技能名称?