@luddinus I’m not sure what you mean by, “if the range is equal, the sql will search the same date, and not in a range.” Do you mean if the user submitted the same date for both the start and end date?
I’d maybe make a query scope that has one required parameter, and an optional second parameter. If the second parameter is null (or the same as the first parameter) you could add a basic WHERE clause; if both parameters are specified and different, then you could search by range:
public function scopeWhereBirthDateIs($query, $start, $end = null)
{
if (is_null($end) || $end == $start) {
return $query->where('birth_date', '=', $start);
}
return $query->whereBetween('birth_date', $start, $end);
}
Then usage:
User::whereBirthDateIs('1989-03-13');
User::whereBirthDateIs('1989-03-13', '1994-05-01');