我正在合并两个表以生成将导出到excel的报告。应该在日期和下拉列表中的参数之间进行过滤
我已经创建了模型,在控制器以及视图中进行了查询。我可以将报告导出到excel,但是不知道如何在控制器和视图中对其进行过滤。这两个表是:
控制器
public function playersPerGame()//public function playersPerGame(Request $request)
{
$games = DB::table('played_game')
->select(DB::raw('count(*) as no_of_players, game'))
->groupBy('game')
->get();
return view('report.playersPerGame', compact('games'));
}
public function playersExport() {
$players = PlayedGame::select(
"game",
\DB::raw("SUM(count(*)) as `no_of_players`"))
//->groupBy("game")
->get();
// Initialize the array which will be passed into the Excel
// generator.
$playersArray = [];
// Define the Excel spreadsheet headers
$playersArray[] = ['Games', 'No. of Players'];
// Convert each member of the returned collection into an array,
// and append it to the payments array.
foreach ($players as $player) {
$playersArray[] = $player->toArray();
}
路线
Route::get('/report/players-per-game', ['as' => 'playersPerGame', 'uses' => 'ReportController@playersPerGame']);
Route::get('/report/players-export', 'ReportController@playersExport')->name('players-export');
视图
<div class="col-xs-4 left-padding">
<a href="{{ route('games-export') }}" class="btn btn-block btn-primary" style="margin-right: 15px;"><i class="fa fa-file-excel-o"></i> Excel</a>
</div>
</div>
</div>
</div>
<div class="box box-primary">
<div class="box-header with-border">
<!--
<div class="box-header with-border">
<div class="box box-info">
-->
<table class="table table-bordered table-hover table-striped table-condensed" id="commenter_info_table">
<caption></caption>
<thead>
<tr>
<td>#</td>
<td>Player</td>
<td>No. of Games</td>
</tr>
</thead>
<tbody>
@foreach($players as $key => $player)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $player->name }}</td>
<td>{{ $player->no_game }}</td>
</tr>
@endforeach
</tbody>
</table>
当我进入查看页面时: