【发布时间】:2015-10-11 20:19:25
【问题描述】:
我正在使用 laravel 5 进行项目。 我在使用不同 ID 的另一个表中使用同一表的同一列 2 次。 现在,当我想在视图页面中分别将两个名称显示为 id 时,它会显示问题..
<div class="tab-pane fade in active" id="tab1primary">
<ul>
<label>PREVIOUS CLUB</label>
{!! Form::select('previous_club_id',$club,null,array('class'=>'form-control')) !!}
</ul>
</div>
<div class="tab-pane fade" id="tab2primary">
<ul>
<label>CURRENT CLUB</label>
{!! Form::select('current_club_id',$club,null,array('class'=>'form-control')) !!}
</ul>
</div>
我已插入数据并成功插入.. 当我显示 id 时,它只显示 id..
<td>{!!$playerhistories->current_club_id!!}</td>
<td>{!!$playerhistories->previous_club_id!!}</td>
但问题是当我想显示以前的俱乐部名称和当前的俱乐部名称时...
<td>{!!$playerhistories->club->name!!}</td>
它显示了这个问题: 试图获取非对象的属性(查看:/var/www/fcimsProject/resources/views/admin/playerhistories/index.blade.php)
我在 playerhistory 模型的 eleqount 中有如下关系:
public function club()
{
return $this->belongsTo('App\Club');
}
在两支球队之间的比赛中,假设阿根廷和巴西我们正在使用俱乐部表并存储双方的俱乐部名称,以及如何在视图页面中显示两个俱乐部名称????
请回复...
【问题讨论】:
-
你必须 create relations in the eloquent model 为你的
$playerhistories。 -
我已经做了一个elewuent并将一个关系描述为: public function club() { return $this->belongsTo('App\Club'); }
标签: php mysql laravel migration project