vendredi 21 février 2020

Use groupBy and foreach

I would need a boost, I can't do it. I use Laravel 5.8 I have a list of registrants for weekly events. I would like for each registrant to display the number of times they participate in each day of the week (Wednesdays, Thursdays and other days) In my controller I group my registrants according to their identifier (ncsa) using "groupBy ()". I get a collection that contains an array of my groups, each line of which is a new collection And after ? I mounted a double foreach () to reach the items of each new collection which I transformed into an array to make this data easier to handle. (????) I turned it all over the place without any results. My internet searches yield nothing How should you proceed knowing that the data obtained is processed in a Blade file? Here is my function of the controller :

public function participation() 
{
$inscrits= DB::table('inscrits')
->select('ncsa','nom','prenom', 'j_semaine')
->get()
->groupBy('ncsa');
foreach ($inscrits as $key => $val)
  { 
foreach($val as $value)
  {
$donnees = array(
'index' => $key,
'nom' => $value->nom,
'prenom' => $value->prenom,
'nbrTotal' => $nbrTotal = $val->count(),
'nbrMercredis' => $nbrMercredis = count([$value->j_semaine = 3]), 
'nbrJeudis' => $nbrJeudis = count([$value->j_semaine = 4]),
'nbrAutres' => $nbrAutres = $nbrTotal -$nbrMercredis - $nbrJeudis, 
        );
return view('Admin.Bilans.participation', compact('donnees'));      
  } 
}

}

thank you for your reply



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire