How do I present in a list on the same row of a groupBy table?

Asked

Viewed 62 times

0

I’m developing a listing and I’m having a hard time presenting on the same row of the table data groupBy I’m not able to list this data on the same line, in case DT_PONTO returns two values S for entry and N for output (and each value has its own ID) and in the html table I wanted these values for two distinct columns.

   public function scopes()
        {


        $workes=Workers::find(20) ;

        $date1 = '2015-10-05';
        $date2 = '2015-10-05';  

        $cargos   =   $workes->cargos()->get('NM_CARGO');
        $pontos   =   $workes->punchcards()->where([
                                                   ['DT_PONTO', '>=', $date1],
                                                   ['DT_PONTO', '<=', $date2]
                                                                            ])
     ->with('markings')->get();   

     foreach($pontos as $valorP){

          $marks = $valorP->markings()->get();
          $resultP[]= $valorP;
        foreach($marks as $mark){
            $resu1=[
                   'CD_PONTO'=>($mark->CD_PONTO),
                   'DT_PONTO'=>($valorP->DT_PONTO),
                   'HR_MARCACAO'=>($mark->HR_MARCACAO)
                 ];





           $tes1[] = $resu1;

        }}

        $retorns1= new Collection($tes1);



        $fills = $retorns1->groupBy('VF_ENTRADA');


        $fills->toArray();

          return view("modules.education.reports.common.table_score_structure", compact( 'retorns','fills'));
            }

1 answer

0


Following a demonstration, it is very vague what you went through but I understood the following.

One of the right ways

$pontos   =   $workes->punchcards()->whereRaw("DT_PONTO <= {$date1}")->whereRaw"DT_PONTO <= {$date2}")->groupBy('column')->get(); // ou troca o get por first para pegar o primeiro

Another way if that’s what I understand

Workers::with('punchcard')->where('id', 20)->whereHas('punchcard', function($query){
  $query->whereRaw('DT_PONTO', '>=', $date1);
  $query->whereRaw('DT_PONTO', '<=', $date2);
})->groupBy('column')->get() // ou pode usar first fiz um código sem testar caso não funcione faça outro WhereHas e passa o dt_ponto no whereRaw com menor igual.
  • When I use the ' whereRaw ' of Syntax error, but in case the relationship is between three Workers table, Punchcards, Markings and groupBy would be for the Markings table in which there is a column that records employee input and output and my main problem and that when passing the data to the VIEW I am not getting in the same row of the html table (Blade) puts a value that records employee entry and exit .

  • Pass two Wherehas then

  • Group By is going to take all the repeat data and it’s going to gather

  • I edited the first whereRaw to be right

Browser other questions tagged

You are not signed in. Login or sign up in order to post.