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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/32mtUo4
via IFTTT

1 commentaire:

  1. As stated by Stanford Medical, It is in fact the one and ONLY reason this country's women live 10 years longer and weigh an average of 42 lbs lighter than we do.

    (And actually, it has totally NOTHING to do with genetics or some secret exercise and really, EVERYTHING about "how" they eat.)

    P.S, I said "HOW", and not "what"...

    TAP this link to determine if this quick test can help you unlock your true weight loss possibility

    RépondreSupprimer