Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

318
Visualizações
Laravel whereBetween with dates why not working?

Here is my code:

$arr = Event::select('user_id', 'start', 'end')
    ->where('start', '!=', $from)
    ->whereBetween('start', [$from, $till])
    ->orWhere(function($query) use ($from, $till) {
        $query->where('end', '!=', $till)
            ->whereBetween('end', [$from, $till]);
    })->get();

start value: 2021-07-11 9:00:00 end value: 2021-07-11 15:00:00

$from value: 2021-07-11 10:30:00 $till value: 2021-07-11 13:00:00

I tried with Carbon as well, but the query result is nothing. What is the problem? Also I tried with:

$arr = Event::where('start', '>', $from)
    ->where('start', '<', $till)    
    ->get();

Simply not working!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The main code segment has some little flaw with

wherebetween('start', [$from, $till])

Because your start date doesn't lies between your from and till value. That returns nothing actually.

Try with your second solution. With a lil change in it.

$arr = Event::where('start', '<=', $from)
->where('end', '>=', $till)    
->get();
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda