I work with an AngularJs/Laravel application. I try to access items in each facture. Actually I can't print out the whole facture object, but I wonder how to access the items so that I can loop trough them and display each.
Here is my Php Controller that send Json data
public function show($id)
{
$facture = Facture::where('id', '=', $id)->with('items')->get();
return Response::json($facture);
}
Here is my simplified AngularJs Controller
$http.get('api/factures/' + $stateParams.factureId).success(function(data) {
$scope.facture = data;
});
And actually
{{facture |json}}prints out this:
[
{
"id": 10200,
"client_id": 1,
"lead_id": 1,
"courtedescription": "Description test",
"etat": "En attente",
"created_at": "2014-12-30 10:01:46",
"updated_at": "2014-12-30 10:01:46",
"items": [
{
"id": 1,
"facture_id": 10200,
"description": "Item numéro 1",
"prix": "15.00",
"tps": "0.75",
"tvq": "1.50",
"grandtotal": "17.25",
"created_at": "2014-12-30 10:01:46",
"updated_at": "2014-12-30 10:01:46"
},
{
"id": 2,
"facture_id": 10200,
"description": "Deuxième item quoi",
"prix": "135.00",
"tps": "6.75",
"tvq": "13.47",
"grandtotal": "155.22",
"created_at": "2014-12-30 10:01:46",
"updated_at": "2014-12-30 10:01:46"
}
]
}
]
Here is a simplified Plunkr to focus on the essential: http://plnkr.co/edit/fZmb4fAX0GJCDH2cpxwQ?p=preview
How could I access the items?