这是我的迁徙:
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这只向我展示了1。当我发现变量的时候,只有第一个季节在里面。
这怎么会发生,因为我定义了一个节目有多个季节。如果有人能给我指明正确的方向,我会非常感激的。
发布于 2019-04-12 21:51:30
在您的上试试这个:
public function seasons()
{
return $this->hasMany('App\Season');
}https://stackoverflow.com/questions/55659666
复制相似问题