2015-02-07 4 views
0

serviciosmotoboy 인 검색어를 작성 중이지만 오늘 날짜가 필요합니다. 해당 특성의 데이터 형식은 timestamp입니다. 나는Laravel에서 오늘의 모든 서비스 받기

Motoboy::with(array('servicios' => function($query){ 
        $query->where('id_estado', '1')->orWhere('id_estado', '2') 
        ->where('fecha_hora', new DateTime('today')); 

       }))->where('auth_token',$auth)->firstOrFail(); 
+0

날짜는 문자열 날짜 ('Ymd H : i : s', 시간())로 전달되어야합니다. mysql을 사용하여 두 개의 타임 스탬프 사이에서 데이터를 얻으십시오 – astroanu

답변

1

new DateTime 객체를 인스턴스화하고 당신이 timestamp에 필요한 형식이없는이 코드 만 doenst 일이. 간단한 솔루션은 원하는 형식을 지정합니다 date() 기능을 사용하는 것입니다, 그래서 현재 timestamp 당신은 당신이 조회하는 것이 좋습니다 것, date('Y-m-d H:i:s')

또한 사용할 것 같은 하루 종일 :

$startToday = date('Y-m-d 00:00:00'); 
$endToday = date('Y-m-d 23:59:59'); 
// ... 
->whereBetween('fecha_hora', array($startToday,$endToday)); 
// .... 

코드는 다음과 같이 바뀝니다.

Motoboy::with(array('servicios' => function($query){ 
    $startToday = date('Y-m-d 00:00:00'); 
    $endToday = date('Y-m-d 23:59:59'); 
    $query->where('id_estado', '1')->orWhere('id_estado', '2')->whereBetween('fecha_hora', array($startToday,$endToday)); 

}))->where('auth_token',$auth)->firstOrFail(); 
+0

이 hora를 가진 서비스를 반환하십시오 ..'' "fecha_hora": "2019-02-08 05:02:00",'' – cheloncio