Php 完整性约束冲突:1052列';教授id';where子句中的Laravel是不明确的

Php 完整性约束冲突:1052列';教授id';where子句中的Laravel是不明确的,php,laravel,laravel-5.2,Php,Laravel,Laravel 5.2,我尝试做的很简单,运行一个带有一些关系的查询,并为该关系提供一个where子句。该查询假设获取具有相关关系的问题,但标记上的where子句告诉我们仅获取具有已发送标记的问题($value) 用户问题模型: <?php namespace App; class userQuestion extends Model { protected $table = "question"; public $primaryKey = "question_id"; protect

我尝试做的很简单,运行一个带有一些关系的查询,并为该关系提供一个where子句。该查询假设获取具有相关关系的问题,但标记上的where子句告诉我们仅获取具有已发送标记的问题($value)

用户问题模型

<?php

namespace App;

class userQuestion extends Model
{
    protected $table = "question";
    public $primaryKey = "question_id";
    protected $fillable = ['question_id'];

    public function gettags() {
        return $this->belongsToMany('App\Profskills','question_profskill',"question_id","prof_id");
    }
}
问题是它给了我这个错误

 QueryException in Connection.php line 729:
 SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'prof_id' in          
 where clause is ambiguous (SQL: select * from `question` where exists 
 (select * from `prof_skills` inner join `question_profskill` on 
 `prof_skills`.`prof_id` =  `question_profskill`.`prof_id` where `question_profskill`.`question_id` =    `question`.`question_id` and 
 `prof_id` = 1) order by `created_at` desc)
该列存在,如果我将该列切换到qp_id(PrimaryKey),它将工作,列将来自我试图访问的透视表

做了一些谷歌搜索,我做的是:

1-put在模型中使用'prof_id'填充(因为我也有数据透视表的模型,所以做了同样的事情)

2-try=>where而不是whereHas

还是卡住了,


谢谢你的帮助

在字段中添加表名,因为两个表中都有prof_id

$allquestions = userQuestion::with('getanswer','getusername','getbounty','gettags')
           ->whereHas('gettags', function($q) use($value) {

       $q->where('question_profskill.prof_id', '=', $value); //question_profskill or prof_skills
})
->orderBy('created_at','Desc')->get();

谢谢,现在我怎样才能把它放在for循环中的哪个位置呢?有多个值?需要更多信息,你的循环是什么,向用户推荐一个由3个标记组成的数组,循环为我用这些标记生成3个where子句!情况就是这样。如果您有多个prof_ID数组,请检查where而不是where
$allquestions = userQuestion::with('getanswer','getusername','getbounty','gettags')
           ->whereHas('gettags', function($q) use($value) {

       $q->where('question_profskill.prof_id', '=', $value); //question_profskill or prof_skills
})
->orderBy('created_at','Desc')->get();