lundi 26 septembre 2016

Laravel Undefined property: stdClass::$opprank

I am absolutely stumped by this issue, where I have tried numerous tests to determine the source of the problem. In my Controller, I assign a number of values to my $players array. When I remove the variable opprank everything works fine. When I have it included however, I get the error message Undefined property: stdClass::$opprank

I have tried dumping the values of $players where the opprank value is shown as expected. I have tried setting it to a static value of '10' as opposed to the DB value but receive the same error. Hopefully someone can spot where I am going wrong...

SystemController.php

            foreach ($teams as $team)
            {
                if ($players[$key]->team == $team->id)
                {
                    // Replace Team ID with Team Short Code for Display Purposes
                    $players[$key]->team = $team->code;

                    $matchups = DB::table('schedule')->where('week', $week->value)->get();

                    foreach ($matchups as $matchup)
                    {
                        if ($team->id == $matchup->home_team)
                        {
                            $opp = DB::table('teams')->select('code', 'rank')->where('id', $matchup->away_team)->first();

                            $players[$key]->opponent = $opp->code;
                            $players[$key]->opprank = $opp->rank;
                            $players[$key]->status = 'Home';
                        }
                        else if ($team->id == $matchup->away_team)
                        {
                            $opp = DB::table('teams')->select('code', 'rank')->where('id', $matchup->home_team)->first();

                            $players[$key]->opponent = $opp->code;
                            $players[$key]->opprank = $opp->rank;
                            $players[$key]->status = 'Away';
                        }
                    }
                }
            }

            foreach ($positions as $position)
            {
                if ($players[$key]->position == $position->id)
                {
                    $players[$key]->position = $position->short_name;
                }
            }
        }

        return $players;
    }
}

players.blade.php

                    <table class="table table-striped table-bordered table-hover" id="dt-players-all">
                        <thead>
                            <tr>
                                <th>Position</th>
                                <th>Player</th>
                                <th>Team</th>
                                <th>Opponent</th>
                                <th>Game</th>
                                <th>Opp. Rank</th>
                                <th>FPPG</th>
                                <th>Salary</th>
                            </tr>
                        </thead>
                        <tbody>

                            @foreach ($players as $player)

                                <tr>
                                    <td></td>
                                    <td> <font color="red"><b></b></font></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td class="center">

                                        @if ($player->opprank <= 10)
                                            <font color="red"><b></b></font>
                                        @elseif ($player->opprank > 10 && ($player->opprank <= 20))
                                            <b></b>
                                        @else
                                            <b><font color="green"></font></b>
                                        @endif

                                    </td>
                                    <td class="center"></td>
                                    <td class="center">$</td>
                                </tr>

                            @endforeach

                        </tbody>
                    </table>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire