Laravel eloquent 一对多关系 where 语句
Laravel eloquent one to many relation where statement
我在laraveleloquent
中有以下型号
class InterviewList extends Eloquent{
protected $table = 'interviewlists';
public function subject(){
return $this->belongsTo('Subject','id_subject','id');
}}
class Subject extends Eloquent{
public function interviewList(){
return $this->hasMany('InterviewList');
}}
我需要获取主题名称为 "java" 的采访列表 table 的 ID,
在主题 table 中,我有 (id,name) 列,在 interviewList table (id,name,id_subject) 中。
我尝试了以下代码
$interviewListId = InterviewList::with('Subject')->whereName('java')->get(array('id'));
但它只是没有给出结果
这样的东西怎么样
Subject::where('name', 'like', '%java%')-> interviewList()->get(array('id'));
要获取主题名称为 java
的采访列表的 ID,您应该使用:
$ids = InterviewList::whereHas('subject', function($q)
{
$q->where('name', 'java');
})->lists('id');
我在laraveleloquent
中有以下型号class InterviewList extends Eloquent{
protected $table = 'interviewlists';
public function subject(){
return $this->belongsTo('Subject','id_subject','id');
}}
class Subject extends Eloquent{
public function interviewList(){
return $this->hasMany('InterviewList');
}}
我需要获取主题名称为 "java" 的采访列表 table 的 ID, 在主题 table 中,我有 (id,name) 列,在 interviewList table (id,name,id_subject) 中。 我尝试了以下代码
$interviewListId = InterviewList::with('Subject')->whereName('java')->get(array('id'));
但它只是没有给出结果
这样的东西怎么样
Subject::where('name', 'like', '%java%')-> interviewList()->get(array('id'));
要获取主题名称为 java
的采访列表的 ID,您应该使用:
$ids = InterviewList::whereHas('subject', function($q)
{
$q->where('name', 'java');
})->lists('id');