There is a multidimensional array:

$filter = [ 'trainer' => \Input::get('trainer', null), 'group' => \Input::get('group', null) ]; $club_id = 1; $data = []; for ( $i = 0; $i <= 12; $i++ ) { $row = null; $row = Row::whereRaw( 'club_id = ' . $club_id . ' and row_weight = ' . $i )->first(); if ($row) { $columns = Column::whereRaw( 'row_id = ' . $row->id )->get(); $rowExit = $this->formStubRow(); foreach ( $columns as $column ) { $time = $column->time; $gym = $column->gym; $status = $column->status; $worker_name = Worker::find( $column->worker_id )->worker_name; $service_title = Service::find( $column->service_id )->service_title; $rowExit[ $column->day ][ $gym ] = [ ]; if( ( $filter[ 'trainer' ] != null && $worker_name == $filter[ 'trainer' ] ) || ( $filter[ 'group' ] != null && $service_title == $filter[ 'group' ] ) || ( $filter[ 'trainer' ] == null && $filter[ 'group' ] == null ) ){ $rowExit[ $column->day ][ $gym ] = [ 'time' => $time, 'gym' => $gym, 'group' => $service_title, 'trainer' => $worker_name, 'status' => $status, 'activate' => true ]; } } array_push( $data, $rowExit ); } else { array_push( $data, $this->formStubRow() ); } Log::debug('WTF IS THIS THEN?!!: '.print_r($filter['group'], true)); } return view('pages.services.indexTimetable', compact('filter'), [ 'data' => $data ] ); } 

Based on it, the table is derived, but I cannot think of how to get closer to editing the object and how to display the data of the trainer and group in the selects.

Tell me, please, how can I substitute variables in order to display the names of groups and trainers in select?

schedule view file:

 @extends('basic.main') @section('page_title') Расписание групповых программ @stop @section('content') <div class="container"> <div class="row"> <div class="text-about"> <h3 class="about-title">РАСПИСАНИЕ ГРУППОВЫХ ПРОГРАММ</h3> </div> {!! Form::open(['class' => 'form-inline', 'method' => 'get', 'route' => ['timetable-show']]) !!} <div id="group-select" class="form-group"> {!! Form::label('filter', ' ', ['class' => 'control-label']) !!}<br> {!! Form::select('filter', $filter, ['class' => 'form-control']) !!} </div> <div id="trainer-select" class="form-group"> {!! Form::label('filter', ' ', ['class' => 'control-label']) !!} {!! Form::select('filter', $filter, ['class' => 'form-control']) !!} </div> {!! Form::submit('применить', ['class' => 'btn btn-default']) !!} {!! Form::close() !!} <div id="table-shedule"> <div id="time-days" class='row' style='clear:both;width:1190px;'> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Пн' }}</p> </div> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Вт' }}</p> </div> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Ср' }}</p> </div> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Чт' }}</p> </div> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Пт' }}</p> </div> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Сб' }}</p> </div> <div id="shedule-day" class='cell' style='width:169px;float:left;text-align: center;min-height:20px;'> <p>{{ 'Вс' }}</p> </div> </div> @foreach( $data as $row ) <div class='row' style='clear:both;width:1200px;'> @foreach( $row as $day=>$gymArray ) <div class='cell' style='width:170px;float:left;;text-align: center;max-height:370px;overflow: auto'> @foreach( $gymArray as $gym=>$gymInfo ) <div class='gym' style='clear:both'> <p>{{ $gymInfo[ 'time' ] or '' }}</p><hr id="hr-time" style="width:20%"/> <strong id="group-name">{{ $gymInfo[ 'group' ] or '' }}</strong><br> {{ $gymInfo[ 'trainer' ] or '' }}<br> <small id="gym-name">{{ $gym or '' }}</small><br> {{ $gymInfo[ 'status' ] or '' }} </div> @endforeach </div> @endforeach </div> @endforeach </div> </div> </div> @stop 
  • What does the table look like in the final version? To edit what object you want to get close? In which selects do you want to display data? Where are these selects? What do the models look like for the entities used? What fields in the involved tables? - VenZell
  • @VenZell added the view table code, when sorting with the selector, the appropriate columns with the trainer data for the group and the hall will be highlighted, hence the editing of the same parameters for the columns - bastadien

1 answer 1

The task was solved in the following way: Array:

 public function index() { $trainers = Worker::all()->toArray(); $trainersArray = [ 'all' => 'все тренеры' ]; foreach( $trainers as $trainer ){ $trainersArray[ $trainer[ 'id'] ] = $trainer[ 'worker_name' ]; } $groups = Service::all()->toArray(); $groupsArray = [ 'all' => 'все группы' ]; foreach( $groups as $group ){ $groupsArray [ $group[ 'id'] ] = $group[ 'service_title' ];} $filter = [ 'trainer' => \Input::get( 'trainer', null ), 'group' => \Input::get( 'group', null ) ]; $club_id = 1; $data = []; for ( $i = 0; $i <= 12; $i++ ) { $row = null; $row = Row::whereRaw( 'club_id = ' . $club_id . ' and row_weight = ' . $i )->first(); if ($row) { $columns = Column::whereRaw( 'row_id = ' . $row->id )->get(); $rowExit = $this->formStubRow(); foreach ( $columns as $column ) { $time = $column->time; $gym = $column->gym; $status = $column->status; $worker_name = Worker::find( $column->worker_id )->worker_name; $service_title = Service::find( $column->service_id )->service_title; $rowExit[ $column->day ][ $gym ] = [ ]; $errors = false; if( $filter[ 'trainer' ] != null && ( $filter[ 'trainer' ] != 'all' && $column->worker_id != $filter[ 'trainer' ] ) ){ $errors = true; } if( $filter[ 'group' ] != null && ( $filter[ 'group' ] != 'all' && $column->service_id != $filter[ 'group' ] ) ){ $errors = true; } if( !$errors ){ $rowExit[ $column->day ][ $gym ] = [ 'time' => $time, 'gym' => $gym, 'group' => $service_title, 'trainer' => $worker_name, 'status' => $status, 'activate' => true ]; } } array_push( $data, $rowExit ); } else { array_push($data, $this->formStubRow()); } } return view('pages.services.indexTimetable', [ 'data' => $data, 'filter' => $filter, 'groups' => $groupsArray, 'trainers' => $trainersArray ] ); } 

View:

 {!! Form::open(['class' => 'form-inline', 'method' => 'get', 'route' => ['timetable-show']]) !!} <div id="trainer-select" class="form-group"> {!! Form::label('group', ' ', ['class' => 'control-label']) !!} {!! Form::select('group', $groups, null, ['class' => 'form-control']) !!} </div> <div id="group-select" class="form-group"> {!! Form::label('trainer', ' ', ['class' => 'control-label']) !!}<br> {!! Form::select('trainer', $trainers, null, ['class' => 'form-control']) !!} </div> {!! Form::submit('применить', ['class' => 'btn btn-default']) !!} {!! Form::close() !!}