Laravel-使用日期之间和下拉菜单进行过滤

时间:2019-05-22 06:33:27

标签: excel laravel

我正在合并两个表以生成将导出到excel的报告。应该在日期和下拉列表中的参数之间进行过滤

我已经创建了模型,在控制器以及视图中进行了查询。我可以将报告导出到excel,但是不知道如何在控制器和视图中对其进行过滤。这两个表是:

  1. 用户(用户:id,名称,用户名)
  2. played_game(PlayedGame:id,user_id,游戏,created_at)

控制器

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>  

当我进入查看页面时:

  1. 我想在导出到excel之前使用日期(played_game.created_at),下拉列表(users.name和play_game.game)之间进行过滤

0 个答案:

没有答案
相关问题