public function getHighlights($match)
 {
     $match = Match::find($match);
     $firstTeam = new TeamRepository(Team::find($match->first_team_id));
     $secondTeam = new TeamRepository(Team::find($match->second_team_id));
     return view("match", compact("match", "firstTeam", "secondTeam"));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //Get all running leagues
     $leagues = League::query()->where("running", "=", true, "and")->where("finished", "=", false)->get();
     $now = new \DateTime();
     if ($leagues) {
         //Foreach league get all matches passed current time
         foreach ($leagues as $league) {
             $matches = $league->matches()->getQuery()->where("starts", "<=", $now, "and")->where("finished", "!=", true)->get();
             if ($matches) {
                 foreach ($matches as $match) {
                     $firstTeam = new TeamRepository(Team::find($match->first_team_id));
                     $secondTeam = new TeamRepository(Team::find($match->second_team_id));
                     $firstTeamTraining = new Training(new TrainingRepository(Team::find($match->first_team_id)));
                     $firstTeamTraining->resetTraining();
                     $secondTeamTraining = new Training(new TrainingRepository(Team::find($match->second_team_id)));
                     $secondTeamTraining->resetTraining();
                     $matcher = new Match($firstTeam, $secondTeam);
                     $matchResults = $matcher->generateActions();
                     //Announce Winner,Looser or draft and give them budget : config("offside.minimum_teams_per_league")
                     if ($matchResults->matchSuccessor == MatchSuccessor::hasWinner) {
                         //We got a winnner
                         $winner = $matchResults->getWinner();
                         $looser = $matchResults->getLooser();
                     }
                     //Get all actions from a single match and make persistence
                     $match->actions()->delete();
                     $this->saveActions($firstTeam, $secondTeam, $match);
                     //save formations
                     $match->firstTeamFormation = $this->getFormationOfCurrentMatch($firstTeam);
                     $match->secondTeamFormation = $this->getFormationOfCurrentMatch($secondTeam);
                     $match->first_team_goals = $matchResults->getTeamGoals($firstTeam);
                     $match->second_team_goals = $matchResults->getTeamGoals($secondTeam);
                     $match->finished = true;
                     $match->save();
                 }
             }
             //After match results are generated check if current league has matches left, if not mark this league as finished
             if ($league->matches()->getQuery()->where("finished", "=", false)->count() == 0) {
                 $league->finished = true;
                 $league->save();
             }
         }
     }
 }
 public function getIndex()
 {
     $matches = $this->league->getMatches();
     $matchesGrouped = [];
     foreach ($matches as $match) {
         $match->first_team_name = Team::find($match->first_team_id)->name;
         $match->second_team_name = Team::find($match->second_team_id)->name;
         $matchesGrouped[$match->starts][] = $match;
     }
     $matchesGroupedWithNumericKeys = [];
     foreach ($matchesGrouped as $match) {
         $matchesGroupedWithNumericKeys[] = $match;
     }
     $teams = [];
     foreach ($this->league->getTeams() as $team) {
         $team = new TeamRepository($team);
         $teams[] = ["name" => $team->getTeamName(), "attack" => $team->getOverallAttack(), "defense" => $team->getOverallDefense(), "stamina" => $team->getOverallStamina(), "creativity" => $team->getOverallCreativity(), "success" => $team->getOverallSuccessConversion(), "user" => $team->getTeamUser(), "level" => $team->getTeamLevel()];
     }
     $javascript = App::make('Javascript');
     $javascript::put(['matches' => $matchesGroupedWithNumericKeys, 'teams' => $teams, 'user' => Auth::user(), 'league_id' => $this->league->getLeagueID()]);
     return view("league", ["league" => $this->league]);
 }
@extends('layout')

@section('content')

@include('partials.menu',['active'=>'Ekipi im'])
<div class="container">
    @include('my-team.partials.menu',['active'=>'Kalendari'])
    <div class="clearfix"></div>
        <div class="tab-calendar">
            <ul class="calendar-games">
                @if($matches)
                    @foreach($matches as $match)
                        <li>
                            <?php 
$date = new DateTime($match->starts);
$home_away = $match->first_team_id == Auth::user()->id ? "Vendës" : "Mysafir";
$oposite_team_name = $match->first_team_id == Auth::user()->id ? \Offside\Models\Team::find($match->second_team_id)->name : \Offside\Models\Team::find($match->first_team_id)->name;
?>
                            <p><i class="fa fa-clock-o"></i>{{ $date->format("d F") }} <span class="c-time">{{ $date->format("G:i") }}</span> </p>
                            <h5>{{ $home_away }}</h5>
                            <h4>vs <span class="c-opponent">{{ $oposite_team_name }}</span></h4>
                        </li>
                    @endforeach
                @endif
            </ul>
        </div>
</div>
@endsection