Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Laravel / Eloquent WHERE NOT SUBQUERY

I`m having trouble to setup a negative condition like such:

WHERE NOT( "last_day" "<=" $first_day OR "first_day" "<=" $last_day)

My query builder looks like this atm:

$query = $query->where(function ($query) use ($first_day, $last_day) {
   $query->where('last_day', '<=', $first_day);
   $query->orWhere('first_day', '<=', $last_day);
});

I would like it to be as such :

$query = $query->whereNot(function ($query) use ($first_day, $last_day) {
  $query->where('last_day', '<=', $first_day);
  $query->orWhere('first_day', '<=', $last_day);
});

To recap: I want an OR statement inside a negative WHERE condition. How can I accomplish this?

source : http://baodad.blogspot.nl/2014/06/date-range-overlap.html

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can play with the logic

$query = $query->where(function ($query) use ($first_day, $last_day) {
   $query->where('last_day', '>', $first_day);
   $query->where('first_day', '>', $last_day);
});
about 4 years ago · Santiago Trujillo Report

0

Went with reverting constraints according to answer found here: Eloquent MYSQL statement : WHERE NOT(A OR B)

$query = $query->where('last_day', '>', $first_day)->where('first_day', '>', $last_day);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!