I am querying from eloquent and receiving records in an array, I need to get each value of the team that is in the records to validate if it is larger or smaller than the value entered in the form.
public function listarLojasParaValidarInsercaoHorarioLoja(string $uuidLoja,array $dados) : string
{
$loja = $this->getByLoja($uuidLoja);
$idLoja = $loja[0]->getLoja()->getId();
$diaSemana = $dados['dia_semana'];
$bancoHorario = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)->get();
$contarBanco = $bancoHorario->count();
if ($contarBanco > 0) {
$aberturaBanco = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)
->get('horario_abertura');
$fechamentoBanco = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)
->get('horario_fechamento');
foreach ($aberturaBanco as $key => $value) {
$horario_abertura = $dados['horario_abertura'];
$horario_fechamento = $dados['horario_fechamento'];
if ($horario_abertura >= $aberturaBanco and $horario_abertura <= $fechamentoBanco || $horario_fechamento <= $fechamentoBanco and $horario_fechamento >= $horario_abertura) {
echo $aberturaBanco;
} else {
echo $aberturaBanco;
}
}
} else {
return False;
}
}
Result var_dump()
[{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}]
I need to get the numbers
if ($horario_abertura >= $aberturaBanco...
part. You may need to add some parentheses to get the ands and ors to interact the way you intend them to.$aberturaBanco = [08:00:00", "08:00:00", "08:00:00","09:00:00"...
?$value
instead of$aberturaBanco
on yourif
condition insideforeach