Catch a certain amount on a Foreach on the Blade

Asked

Viewed 490 times

0

I wanted to know how I do to walk through a Collection and result a certain value? The Collection works like this and returned various values of employee appointments to be printed on the point, there are two stop meters that considers each marking $markings->VF_ENTRADA returning S for entry and N outgoing $markings->HR_MARCACAO which represents the time of this marking I’m facing a problem to pick the final time of output, of course this last output representing the closing point would be last value of the returned array but there may be editing cases in DB. Summing up I wanted to catch the biggest time HR_MARCACAO worthwhile VF_ENTRADA = N which would represent the last departure of the employee thus closing of the day point.

This is the code I’m using to list on Blade

  ($markings->VF_ENTRADA (RETORANAR VALOR = 'S' OU 'N'))

    <td class="pl-0 pr-0 pb-0 text-center">


           @foreach ($punchcard->markings as $markings)
              @if($loop->last)

                   {{$markings->HR_MARCACAO}}
              @endif

            @endforeach

    </td>

I’m using $loop->last to return the last interaction, but as I said there may be editing cases in DB so this value could be invalid for the result I want.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Search query

public function returnDataPonto($id,$periode_start,$periode_stop)
    {

      $worker=Workers::where('CD_FUNC',$id)->with('cargos')
                                         ->whereHas('punchcards',function($query)
                                        use($periode_start,$periode_stop){

    $date1 = $periode_start;
    $date2 = $periode_stop;

    $query->where('DT_PONTO','>=', $date1)
          ->where('DT_PONTO','<=', $date2);})     


          ->whereHas('punchcards.markings',function($query){
            $query->where('VF_ENTRADA', 'N');
            })
          ->first();

        return $worker;
    }
  • do a dd($punchcard->markings) and put in the question please

  • open a markings please so it is easier to guide you

  • Posted there, I could not display the content of each tag because it was truncated because of the so much content.

  • I want to understand the return of the data so I make a very clear answer

  • I posted the return in Json

  • Hr_score is a team so?

  • If you want to get HR_MARCACAO from VF_ENTRADA to be N you can do this simply with Query Builder Pow, if that’s what I understand I can build an example for you.

  • That’s right and a team that takes the exact time of the scoring

  • is that what I said above?? Catch HR_MARCACAO from VF_ENTRADA to be N ?

  • And so when an employee passes his badge and made the time log and whether he entered or left.

  • I get it, but you’re using too much PHP and too little bank, certain things let the bank do.

  • I posted the search query that I made a peek.

  • In the case of this query I also use to pick the input time too

  • You can use the query below that I answered with whereHas('markings',Function($query){}) and validate VF_ENTRADA

  • I tried it the way I said, only the relationship disappeared and ended up not returning any value or error message.

  • Put the code on so I can see

  • I updated the response and put relational Where for you to understand what I said.

Show 12 more comments

1 answer

0


Answer to your question can be resolved as follows:

On the controller:

$marcacoes = Model::select('HR_MARCACAO')->where('VF_ENTRADA', 'N')->get(); //Dessa forma você pega somente o HR_MARCACAO do VF_ENTRADA n, se quiser todos dados além do HR_MARCACAO só tirar o select

Where relational:

$worker=Workers::where('CD_FUNC',$id)->with('cargos')->whereHas('punchcards',function($query) use($periode_start,$periode_stop)
{
        $query->where('DT_PONTO','>=', $periode_start)->where('DT_PONTO','<=', $periode_stop);

})whereHas('punchcards.markings', function($query){
  $query->where('VF_ENTRADA', 'N');
})->first();

In the Blade:

@foreach($marcacoes as $marcao)
  @if($loop->last)

      {{$markings->HR_MARCACAO}}

   @endif
@endforeach

If you don’t help me answer that I will see you again and help you solve.

  • I edited the way I said, just be taking the relationship of Positions. I edited my code there to see.

  • and the return is what?

  • Gave an infinite loop, that ai own Lockable to kkk

  • Wrong was endless loop no, I think what was returned were all the data from markings without relating to a particular employee

  • Look at your bank if you’re right, because if you’re wrong you need to redo

  • right he ta, I have tested take data by command line was quiet.

  • Do a test without all this Where just uses the last whereHas and see if it returns the data

  • Without Where nothing returns no. I’m thinking of another way to treat, because like this in the first version I showed you it returns all the appointments I need the key and I can separate it as the time the employee enters and the time he leaves and closes the point that in case would be the biggest time scheduled.

  • Make a map of your tables something must be wrong, because I have tables related this way and returns right '-'

  • 1

    Face the anger that I’m going through I would even see, the problem that is the company’s DB and they want to maintain the integrity of DB, but thanks anyway Lucas Antonio helped a lot.

Show 5 more comments

Browser other questions tagged

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