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

1 commentaire:

  1. Water Hack Burns 2lb of Fat OVERNIGHT

    Over 160,000 men and women are utilizing a easy and secret "liquid hack" to drop 2 lbs every night while they sleep.

    It's painless and it works on anybody.

    This is how you can do it yourself:

    1) Take a glass and fill it up with water half full

    2) And then do this amazing hack

    and be 2 lbs thinner as soon as tomorrow!

    RépondreSupprimer