这是我的迁移
y = ele.find('div', attrs = {'class':'ListingData'}).get_text().replace("\n","").strip()
例如输出哪个
Schema::create('seasons', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('show_id')->unsigned();
$table->bigInteger('season');
$table->timestamps();
});
Schema::table('seasons', function(Blueprint $table) {
$table->foreign('show_id')->references('id')->on('shows');
});
然后在# id, show_id, season, created_at, updated_at
'1', '1', '1', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'2', '1', '2', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'3', '1', '3', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'4', '1', '4', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'5', '1', '5', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'6', '1', '6', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'7', '1', '7', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'8', '1', '8', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'9', '1', '9', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
'10', '1', '10', '2019-04-12 21:04:40', '2019-04-12 21:04:40'
模型中,我有了这个
Show
现在在我的刀片文件中,当我要显示特定的节目时,我试图回显所有的季节数字。
public function seasons()
{
return $this->hasMany('App\Season', 'season');
}
这仅显示@foreach($show->seasons as $season)
{{ $season->season }}
@endforeach
。当我dd变量时,只有第一个季节在其中。
这是怎么发生的,因为我定义一个节目有多个季节。如果有人能指出我正确的方向,我将不胜感激。
答案 0 :(得分:1)
在您的Show模特上尝试一下:
public function seasons()
{
return $this->hasMany('App\Season');
}