반응형
사용자가 로그인할 때 update_at 열을 업데이트하는 방법은 무엇입니까?
업데이트 하려고 합니다.updated_at사용자가 로그인할 때마다 현재 시간까지 열을 선택합니다.
하지만 다음과 같은 오류가 발생합니다.
잘못된 인수예외 4자리 연도를 찾을 수 없습니다 데이터가 없습니다.
PHP
$input = Input::all();
$remember = (Input::has('remember')) ? true : false;
$auth = Auth::attempt([
'username' => $input['username'],
'password' => $input['password'],
'active' => 1
],$remember
);
if ($auth)
{
$user = Auth::user();
$user->updated_at = DB::raw('NOW()');
$user->save();
if ($user->userType==1)
{
return Redirect::intended('admin');
}
elseif ($user->userType==2)
{
return Redirect::intended('corporate');
}
elseif ($user->userType==3)
{
return Redirect::intended('trainer');
}
elseif ($user->userType==4)
{
return Redirect::intended('user');
}
}
웅변법을 사용할 수 있습니다.touch()다음의 경우:
//instead of
$user->updated_at = DB::raw('NOW()');
$user->save();
// simply this:
$user->touch();
하나는 update_at 열이 기본 타임스탬프 이름이기 때문에 사용하지 않을 것입니다.
last_login을 사용하는 것이 좋습니다.
그리고 그냥 PHP date 방법을 사용하세요.
$user->updated_at = date('Y-m-d G:i:s');
도움이 되길 바랍니다.
배열 구문을 사용하는 대신 실수로 값을 할당하는 것 같습니다.예:
Model::create([
'key'='val'
]);
대신:
Model::create([
'key'=>'val'
]);
언급URL : https://stackoverflow.com/questions/23132758/how-to-update-the-updated-at-column-when-the-user-logs-in
반응형
'programing' 카테고리의 다른 글
| 개체가 아닌 속성을 가져오는 중 (0) | 2023.09.10 |
|---|---|
| 스프링 JPA :: 형식에서 변환할 수 있는 컨버터를 찾을 수 없습니다. (0) | 2023.09.10 |
| 패치를 적용할 때 충돌을 해결할 수 있는 방법이 있습니까? (0) | 2023.09.10 |
| UIT 텍스트 보기에서 텍스트를 세로로 가운데 배치 (0) | 2023.09.10 |
| 종속 자식 이미지가 있는 도커 이미지를 삭제할 수 없습니다. (0) | 2023.09.10 |