programing

사용자가 로그인할 때 update_at 열을 업데이트하는 방법은 무엇입니까?

elecom 2023. 9. 10. 11:56
반응형

사용자가 로그인할 때 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

반응형