Laravel 5 Query builder

65 views Asked by At

I tried advanced where clauses

i have model with 2 datetime columns start and end

the request comes two values date_start, date_end

my code

->where(function($q) use ($date_start,$date_end) {
                $q->where('start','>=',$date_start)
                  ->where('end','<=',$date_start)
                  ->where('start','>=',$date_end)
                  ->where('end','<=',$date_end);
            })
            ->first();

code returned nothing but in table have one record, values on request suitable. What is wrong?

1

There are 1 answers

0
Rai On

worked

$q->where('start','<=',$date_start)
  ->where('start','<',$date_end)
  ->where('end','<=',$date_end);