【发布时间】:2015-10-19 05:36:14
【问题描述】:
我有一个带有字段的俱乐部表:
id,name,est_date,CEO ....
我有球员表有字段:
id, name,DOB,height,weight, .....
player_histories 表:
id,player_id,previous_club_id,current_club_id,position, ......
club_histories 表:
club_id, championship_id,status, ...
在 club_histories 的查看页面中,我可以显示:
club name,championship name and status...
但我也想在 club_histories 表中显示俱乐部的相应球员......这怎么可能??? 请回复...
编辑部分:添加代码
Routes.php:
Route::resource('clubhistories','ClubHistoryController');
ClubHistoryController.php:
public function show($id,ClubHistory $clubhistories)
{
$club=$clubhistories->find($id);
$clubhistories=$clubhistories->getPlayerByCLub();
return view('pages.singleClub',compact('club','clubhistories'));
}
ClubHistoryRepository.php
public function getPlayerByCLub(){
return $this->makeModel() ->join('clubs', 'clubs.id', '=', 'club_histories.club_id')
->join('player_histories','player_histories.current_club_id', '=', 'clubs.id')
->join('players', 'players.id', '=', 'player_histories.player_id')
->get([
'clubs.name',
'player_histories.player_id',
'players.name',
]);
}
SingleClub.blade.php:
<div class="tab-content">
<div class="tab-pane in active" id="basic">
<table class="table table-condensed">
<thead>
<tr>
<th>Name</th>
<th>contact</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name:</td>
<td>{!!$club->club->name!!}</td>
</tr>
<tr>
<td>Contact:</td>
<td>{!!$club->club->contact_no!!}</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="players">
<table class="table table-condensed">
<thead>
<tr>
<th>Player name</th>
<th>Position</th>
</tr>
</thead>
<tbody>
@foreach($clubhistories as $clubhistories)
<tr>
<td> {!! $clubhistories->name!!} </td>
<td> {!! $clubhistories->position!!} </td>
</tr>
@endforeach
</tbody>
</table>
</div>
上面使用的加入和您给出的解决方案给出了相同的解决方案..我想将俱乐部对象中的俱乐部历史找到的相同 id 传递给俱乐部历史对象,以便显示俱乐部的所有球员.. 你能帮帮我吗..
【问题讨论】:
-
如果您愿意,请考虑遵循以下简单的两步操作: 1. 如果您还没有这样做,请提供适当的 DDL(和/或 sqlfiddle),以便我们可以更轻松地复制问题。 2. 如果您尚未这样做,请提供与步骤 1 中提供的信息相对应的所需结果集。
标签: php mysql laravel migration project