2017-05-14 7 views
0

Carbon을 사용하여 PHP에서 MySQL을 사용하여 Carbon을 관리하는 데 별 어려움이 없지만 간단한 Insert 문과 관련된 문제가 있습니다. 내가 Medoo을 사용하고 SQL 문을 실행하려면이 내 코드를 삽입하는 것입니다삽입 문을 실행할 때 탄소 (C) 날짜가 비어 있습니다.

public function register($code, $fullname, $address, $phones, $email, $now){ 

    $registration = $this->_app['medoo']->insert("customers",[ 
     'cus_code' => $code, 
     'cus_fullname' => $fullname, 
     'cus_address' => $address, 
     'cus_phone_s' => $phones, 
     'cus_email' => $email, 
     'created_at' => $now 
    ]); 


    return $registration; 

} 

을 내가 값을 통과 곳이다 : 문은 오류가 반환

$code = $request->get('code'); 
$name = $request->get('name'); 
$phones = $request->get('phone_s'); 
$address = $request->get('address'); 
$email = $request->get('email'); 
$now = Carbon::now('America/Monterrey'); 

$customer_registration = $app['customer.model']->register($code, $name, $address, $phones, $email, $now);` 

if($customer_registration){ 
    $request_status = true; 
}else { 
    $request_errors[] = "Ocurrio un error al registrar el cliente"; 
} 

을이 출력입니다 나는 그것을 디버깅하는 경우 :

INSERT INTO "customers" 
("cus_code", "cus_fullname", "cus_address", "cus_phone_s", "cus_email", "created_at") 
VALUES 
('n20', 'notaria 20', 'lerdo 202', '1234567890', '[email protected]') 

당신이 볼 수 있듯이, 날짜가없는 나는 내 함수 내에서 그것을 에코 경우 때문에 어떤 이해가되지 않습니다 ...

public function register($code, $fullname, $address, $phones, $email, $now){ 
    echo '<p>this is the variable now: '.$now.'</p>'; 
    $this->_app['medoo']->debug()->insert("customers",[ 
     'cus_code' => $code, 
     'cus_fullname' => $fullname, 
     'cus_address' => $address, 
     'cus_phone_s' => $phones, 
     'cus_email' => $email, 
     'created_at' => $now 
    ]); 

    die(); 

    return $registration; 

} 

출력은 ...

this is the variable now: 2017-05-14 00:52:00 

    INSERT INTO "customers" 
    ("cus_code", "cus_fullname", "cus_address", "cus_phone_s", "cus_email", "created_at") 
    VALUES 
    ('n20', 'notaria20', 'lerdo 202', '1234567890', '[email protected]') 

나는 날짜 지금 $를 변경 ('Y-m-D H : m : s'를) 및 그것은 작동하지만, 내 앱 나는 탄소를 사용해야합니다.

나는 이것으로 분명해 졌으면 좋겠다. 나는 영어로 잘하지 않는다. 제발 도와 줘!

+0

같이해야합니까? – Exprator

+0

예 Carbon \ Carbon을 사용했습니다. ' – DaveSanchez

+0

그냥 Carbon :: now()를 건네주고 날짜를 알려주는지 확인하십시오. – Exprator

답변

0

이 질문에 대한 답변은 댓글에 포함되어 있으며 게시 할 수있는 방법이 아니므로 여기에 답변을 게시하여 질문을 닫습니다.

는 여기에서 그는 created_atupdated_at 값에 영향을주지 않습니다 laravel의 insert()SQL 형식으로 타임 스탬프를 전달해야하고 created_at 값을 추가하기 위해 수작업을 필요로하기 때문에 올바른 방법은 수동으로해야 insert() 방법으로 그것을 전달 :

Carbon::now('America/Monterrey')->format('Y-m-d H:m:s'); 
는 따라서 코드는 모두 컨트롤러와 모델에 탄소 클래스 수입이 되었습니까

$now =Carbon::now('America/Monterrey')->format('Y-m-d H:m:s'); 
$this->_app['medoo']->debug()->insert("customers",[ 
     'cus_code' => $code, 
     'cus_fullname' => $fullname, 
     'cus_address' => $address, 
     'cus_phone_s' => $phones, 
     'cus_email' => $email, 
     'created_at' => $now 
    ]);