您好我是新來laravel,我想我的登錄表單的代碼功能這裏是代碼:
我這是怎麼創建新的用戶(作品井)
public function action_newuser()
{
$email = Input::get('email');
$password = Input::get('password');
$new_user = Input::get('new_user', 'off');
$first_name= Input::get('firstname');
$last_name= Input::get('last_name');
$username= Input::get('username');
$user = new User();
$user->email = $email;
$user->password = Hash::make($password);
$user->first_name =$first_name;
$user->last_name= $last_name;
$user->username= $username;
try{
$user->save();
}
catch(Exception $e) {
echo "Failed to create new user!";
}
這是我的登錄功能:
public function action_login()
{
$password = Input::get('password');
$username= Input::get('username');
$remember= Input::get('remember', 'off');
if($remember =='off') $remember=FALSE;
if($remember =='on') $remember=TRUE;
$credentials = array(
'username' => $username,
'password' => $password,
'remember' => $remember
);
if(Auth::attempt($credentials))
{
return Redirect::to('dashboard/index');
}
else
{
#I put this line to check are the values passed from my form are correct.
echo $password.' ' .$username.' '. $remember;
}
}
當我提交的登錄表單,總是顯示空白頁面有$的密碼,用戶名$值$和記值。這意味着Auth :: attempt()運行不正常。
可能是什麼問題?
是'$記「真的是憑證嗎? –
@WaleedKhan沒有問題。 Auth :: attempt將數組作爲參數('username','password','remember') – Hasan
@HananAyan不是真的,內建的記憶是嘗試的第二個參數(數組$ remember,boolean $ remember)。第一個數組中的其他參數是您嘗試匹配的用戶列,如在where子句中。 http://laravel.com/docs/security#authenticating-users – brazorf