withing my view I have access to a collection of FoodTypes. I have cast it to an array to make it easier to display
array:2 [▼
0 => array:7 [▼
"id" => 1
"name" => "Frozen"
"value" => "NOC M1"
]
1 => array:7 [▼
"id" => 2
"name" => "Fresh"
"value" => "NOC A1"
]
]
Initially, I had a Model for each individual FoodType e.g. Frozen and Fresh Models, but I soon discovered that their tables/data were identical, so it seemed wrong to do this. Now I have a generic Model, with the name defining the type of food.
Anyways, when I had a Model for each type, it was simple to do a count on the number of particular types. Now however, I find myself doing something like this
count($data->foodTypes)
The problem is, I need to display the number for each individual type. The above will return 2 because it does not take the name into consideration. So in essence, I need to do something like the following
count($data->foodTypes->where('name', '=', 'Frozen'))
Would something like this be possible?
Thanks
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1nl2ecM
via IFTTT
Aucun commentaire:
Enregistrer un commentaire