1

I am fairly new to AngularJS and I am working a new project with Laravel 5 and AngularJS.

So basically, I am trying to update the standings depending on some filters.

Here is how I call my api:

$http.post('/api/standings', {
        category: $scope.current_category.id,
        division: $scope.current_division.id,
        gender: $scope.current_gender.slice(0,1),
        season: $scope.current_season.id
    }).
    success(function(data, status, headers, config) {
        var standings_array = [];
        var stats_array = [];

        angular.forEach(data, function(value,key){
            standings_array[key] = value[0];
            stats_array[key] = value[1];
        });

        $scope.standings = standings_array;
        $scope.team_stats = stats_array;
    });

And this is how I return the array:

 $teams_array[] = array($team,$stats);
 return $teams_array

And my view:

  <tr ng-repeat='team in standings'>
        <td><% $index+1 %></td>
        <td><% team.name %></td>
        <td><% team_stats[$index].games_played %></td>
        <td><% team_stats[$index].points %></td>
        <td><% team_stats[$index].win_pct %></td>
  </tr>

Everything is fine, except for the win_pct, as it's a model accessor:

public function getWinPctAttribute()
{
    $pct = Utils::calculatePercentage($this->points,$this->games_played*3);
    $pct = number_format($pct, 2);

    return $pct;
}

But the win_pct is returning nothing... Is there a way for me to access that value?

Thanks, Ara

1 Answer 1

1

You need to add protected $appends = ['win_pct']; in your Model. Check Eloquent section from Laravel 5 Documentation http://laravel.com/docs/5.0/eloquent last paragraph.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.