我想算的时间,用户登录量以下是我正在试图做到这一点:计数次用户登录
呼叫的用户与
$user = User::find(Auth::user()->id);
之后,我试图访问DB次数达到用户登录量使用
$logincount = $user->logincount;
,然后我想用这条线来增加变量
++$logincount;
最后我试图保存用户和重定向返回预期页面:
$user->save();
return Redirect::intended('/');
我登录后,检查数据库,在“logincount”字段中的号码不会增加我登录并重定向到正确的页面。我datadumped/vardumped $用户变量,它表明用户仍然是0.不知道是什么问题,因为我刚开始学习编程。我真的很感谢一些帮助。谢谢!
这里就是整个功能:
public function postSignIn() {
$validator = Validator::make(Input::all(), array(
'email' => 'required',
'password' => 'required'
));
if ($validator->fails()) {
//Redirect to sign in page
return Redirect::route('home')->withErrors($validator)->withInput();
} else {
//Checks if user checked true or false
$remember = (Input::has('remember')) ? true : false;
//Attempt use sign in
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1
), $remember);
if ($auth) {
//Increment login count
$user = User::find(Auth::user()->id);
$logincount = $user->logincount;
++$logincount;
$user->save();
//Redirect to the Intended Page
return Redirect::intended('/');
} else {
return Redirect::route('home')->with('global', 'Email or Password Incorrect or account not activated');
}
}
return Redirect::route('home')->with('global', 'There was a problem signing you in :(');
}
你所增加的本地副本如果计数器的值。不是柜台。 – MightyPork
'$ logincount = $ user-> logincount;'应该是'$ user-> logincount ++;'' – Farkie