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.
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
– Lucas Antonio
open a markings please so it is easier to guide you
– Lucas Antonio
Posted there, I could not display the content of each tag because it was truncated because of the so much content.
– Richard carlos
I want to understand the return of the data so I make a very clear answer
– Lucas Antonio
I posted the return in Json
– Richard carlos
Hr_score is a team so?
– Lucas Antonio
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.
– Lucas Antonio
That’s right and a team that takes the exact time of the scoring
– Richard carlos
is that what I said above?? Catch HR_MARCACAO from VF_ENTRADA to be N ?
– Lucas Antonio
And so when an employee passes his badge and made the time log and whether he entered or left.
– Richard carlos
I get it, but you’re using too much PHP and too little bank, certain things let the bank do.
– Lucas Antonio
I posted the search query that I made a peek.
– Richard carlos
In the case of this query I also use to pick the input time too
– Richard carlos
You can use the query below that I answered with whereHas('markings',Function($query){}) and validate VF_ENTRADA
– Lucas Antonio
I tried it the way I said, only the relationship disappeared and ended up not returning any value or error message.
– Richard carlos
Put the code on so I can see
– Lucas Antonio
I updated the response and put relational Where for you to understand what I said.
– Lucas Antonio