I am sure this question has been already asked before, but I could not see or find a best explanation of it, therefore I would like to re-ask the same question and open the thread for more clear answers with some examples.
My goal is to display teams and its ranking, note: for displaying ranking I have a separate function that gets the ranking of team depending on their score field in db.
I have two functions within a TeamController as below:
tm.showAllByClass = function (classId) {
TeamService.showAllByClass(classId).then(function (response) {
tm.teamsInClass = response.data;
}).catch(function (error) {
$scope.result = error;
});
};
tm.ranking = function (classId, teamId) {
TeamService.ranking(classId, teamId).then(function (response) {
return response.data;
}).catch(function (error) {
$scope.result = error;
});
};
<tr ng-repeat="tm in team.teamsInClass.data">
<td>{{tm.group_number}}</td>
<td>{{tm.role.name}}</td>
<td>{{tm.ranking(tm.class_id, tm.id)}}</td>
<td>{{tm.amount | currency}}</td>
</tr>
And this is the function in backend part that gets all teams:
public function findAllTeamsInClass($classId)
{
return Team::where('class_id', '=', $classId)->with('role', 'business')->get();
}
// return rank of team
public function teamRanking($classId, $teamId){
return 3; // for sake of simplicity I just return a static value
}
Is there any way I can attach teamRanking function directly to the team entitiy as relationship or something?
For some reason tm.ranking() is not returning anything, how can I call a function that returns a value within the ng-repeat.