2014-04-17 7 views
13

Próbuję zaktualizować updated_at kolumnę do chwili obecnej, za każdym razem, gdy użytkownik loguje wpróby aktualizacji „updated_at” kolumny gdy użytkownik loguje się błąd: a. Cztery cyfry roku nie mógł znaleźć brakujących danych

.

Ale otrzymuję ten błąd:

InvalidArgumentException A four digit year could not be found Data missing

kod:

$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'); 
    } 
} 
+0

Co otrzymasz, gdy zrzucić '$ user-> updated_at' –

Odpowiedz

41

Można użyć wymowny dotyk() metoda na to:

//instead of 
$user->updated_at = DB::raw('NOW()'); 
$user->save(); 

// simply this: 
$user->touch(); 
4

Dla jednego nie użyłbym kolumnę updated_at jak to domyślna nazwa znaczniki czasu.

Użytkownik będzie lepiej z last_login

I po prostu użyć metody data PHP.

$user->updated_at = date('Y-m-d G:i:s'); 

Mam nadzieję, że to pomoże.

+1

W zależności od aplikacji, nie widzę dlaczego używając updated_at jest wyłączony granice. Czy nie do tego służy aktualizacja_at? – PaulELI

0

myślę, że przypadkowo przypisanie wartości zamiast używać składni tablicy. np:

Model::create([ 
    'key'='val' 
]); 

zamiast:

Model::create([ 
    'key'=>'val' 
]); 
Powiązane problemy