我在 laravel eloquent 中有以下模型
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”的 interviewList 表的 ID, 在 subject 表中我有(id,name)列,在 interviewList 表中有(id,name,id_subject)。 我试过下面的代码
$interviewListId = InterviewList::with('Subject')->whereName('java')->get(array('id'));
但是没有结果
最佳答案
这样的事情怎么样
Subject::where('name', 'like', '%java%')-> interviewList()->get(array('id'));
关于php - Laravel Eloquent 一对多关系 where 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060683/