Feeling like I'm doing my function wrong
Hey everyone because my code is long as i've used alot of bootstrap theming im just going to try and breakdown what i have done and why i feel its wrong, and maybe someone can offer a solution.
♦ I have 80 users which can be part of many groups ♦ I have 100 Groups in my database ♦ each one of these groups has many streams I have 1080 streams in total
I have an API I created a while back for grabbing statistics on each stream, which I then use. I have created a function called streamData() in the groups model which basically sends a get request to my API and returns it.
stream 1 -> streamData() which then returns lets say 27 listeners for example: I then have a function in my view with a nested foreach
foreach groups as group
foreach group->streams as stream
if stream->streamData() == -2
"uh oh, something is wrong!"
else
stream->streamData() // show the data
endif
endforeach
endforeach
This code above is all in my view and it just feels wrong this is what I would like to do but i dont know how i can do it in laravel
public function index()
{
$groups = group::all();
foreach ($groups as $groups){
foreach ($group->streams as $stream){
$listeners[] = $stream->streamData() // add the data into this array
}
}
return view('dashboard', compact('listeners'));
}
Please or to participate in this conversation.