Laravel - Фильтр между датами и выпадающим - PullRequest
0 голосов
/ 22 мая 2019

Я объединяю две таблицы для создания отчета, который будет экспортирован в Excel. Это должно быть отфильтровано с использованием даты и параметра в выпадающем списке

Я создал модель, запрос в контроллере, а также представление. Я могу экспортировать отчет в Excel, но не знаю, как его отфильтровать в контроллере и просмотреть. Две таблицы:

  1. пользователей (пользователь: id, имя, имя пользователя)
  2. plays_game (PlayedGame: id, идентификатор_пользователя, игра, create_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. Я хочу отфильтровать данные между датами (plays_game.created_at), выпадающими списками (users.name и plays_game.game) перед экспортом в excel
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...