我的迁移中有以下内容:
public function up()
{
Schema::create('plan_submissions', function (Blueprint $table) {
$table->bigIncrements('id');
//This is the advisor_id for the advisor who created the Plan Submission
$table->unsignedBigInteger('advisor_id')->index();
$table->timestamps();
$table->softDeletes();
$table->foreign('advisor_id')->references('id')->on('advisors');
我的计划提交模型中包含以下内容:
public function advisor()
{
return $this->belongsTo(Advisor::class);
}
顾问模型的主键是'id'。
我的控制器中的If / Else语句中包含以下内容:
elseif (request('advisor_last_name')) {
PlanSubmission::whereHas('advisor', function ($query) {
$query->where('last_name', request('advisor_last_name'))->paginate(25)->appends('advisor_last_name', request('advisor_last_name'));
});
我收到以下错误消息:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'plan_submissions.advisor_id' in 'where clause' (SQL: select count(*) as aggregate from `advisors` where `plan_submissions`.`advisor_id` = `advisors`.`id` and `last_name` = bayne)
我不明白为什么会出现此错误消息
答案 0 :(得分:0)
在您的计划提交模型中尝试
public function advisor()
{
$this->belongsTo('App\Advisor', 'advisor_id', id);
}