나는 필드에 약속 시작 날짜와 시간을 저장하는 appointments table
을 가지고 있습니다. 특정 날짜 또는 두 주어진 날짜 사이에 시작하는 약속을 얻는 데 사용하는 여러 가지 방법이 있습니다.날짜 사이의 Laravel 검색 결과가 동일하지 않을 때 결과가 일치하지 않음 (오늘부터 결과 얻기)
달력 클래스 : 예를 들어
public function today()
{
$start = Carbon::now()->hour('00')->minute('00')->second('00');
$end = Carbon::now()->hour('23')->minute('59')->second('00');
return Appointment::getAppointments($this->start, $this->end);
}
// public function tomorrow();
// public function thisMonth();
약속 모델 :
public static function getAppointments($start, $end)
{
return static::whereBetween('date', array(
$start->format('Y-m-d H:i'),
$end->format('Y-m-d H:i')
))->get();
}
당신은, 그렇지 않으면 어떤 결과를 반환하지 않기 때문에 나는, 시간, 분, 초를 설정해야 볼 수 있듯이 시작일과 종료일이 같으면 다음을 수행하고 그 날짜로부터 결과를 얻는 것이 가능합니까?
public function today()
{
$start = Carbon::now();
$end = Carbon::now();
return Appointment::getAppointments($this->start, $this->end);
}
public static function getAppointments($start, $end)
{
return static::whereBetween('date', array(
$start->format('Y-m-d'),
$end->format('Y-m-d')
))->get();
}
날짜 사이에 떨어질 것이다, 그래서이 Ymd 일수에 날짜를 변환해야합니다
컨트롤러의 상단에있는 DB 네임 스페이스를 가져올 수 있는지 확인 생일을 검색하지만 월과 일로 검색합니다. 이런 약속에도 내가 이것을 사용할 수 있는지 몰랐다. 굉장, 고마워요 :) – Hardist