gpt4 book ai didi

php - 无法在 Blade 中显示两列结果,laravel 5.1

转载 作者:行者123 更新时间:2023-11-29 11:52:08 25 4
gpt4 key购买 nike

我试图在模板中显示两个表的列,但没有成功

模板:

@foreach ($LatestSeeker_list_adv as $ads)
<span>ads id</span><span>{{ $ads->advertise->id }}</span>
<span>inf id</span><span>{{ $ads->information->id }}</span>
@endforeach

Controller :

public function SeekerLatest()
{
$LatestSeeker_list = Advertise_Model::with('information')->get();

return view('Users.Seeker.LatestAds.index',compact('LatestSeeker_list'));
}

广告模型:

public function Information()
{
return $this->hasOne('App\Information_Model');
}

信息模型:

public function Advertise()
{
return $this->belongsTo('App\Advertise_Model');
}

广告迁移:

Schema::table('advertise', function($table) {
$table->foreign('information_id')->references('id')->on('information');
});

错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'information.advertise__model_id' in 'where clause' (SQL: select * from information where information.advertise__model_id in (1, 2))

最佳答案

您需要定义关系列,以便 Laravel 知道需要选择哪些行来显示关系。

public function Information()
{
return $this->hasOne('App\Information_Model', 'id', 'information_id');
}

参见http://laravel.com/docs/5.1/eloquent-relationships#one-to-one了解更多信息

关于php - 无法在 Blade 中显示两列结果,laravel 5.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33891070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com