$checks = User::query()
->byNotWhereAdmin()
->with(['checks' => function (HasMany $query) {
$query->when($this->selectDate, function ($query) {
$query->whereDate('check_in', $this->selectDate);
}, function ($query) {
$query->whereDate('check_in', $this->yesterday_date);
});
}]);
$checks = User::query()
->byNotWhereAdmin()
->with(['checks' => function (HasMany $query) {
return $query->when($this->selectDate || $this->selectDate2, function ($query) {
$query->whereBetween('check_in', [$this->selectDate, Carbon::parse($this->selectDate2)->addDays(1)]);
}, function ($query) {
$query->whereDate('check_in', $this->yesterday_date);
});
}]);
i want to do it with between 2 date parameters in datepicker range. i have done the same in belongsTo builder but revers function where i call Check::with(['users => function (BelongsTo $query)])