0
当我提交我的用户凭证而不是在表单中尝试将我注册为新用户时。以laravel形式登录用户试图注册时
这里是我的控制器:
public function postCreate() {
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if ($validation->passes()) {
$user = new User;
$user->username = Input::get('username');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::route('home')->with('message', 'Thanks for registering');
} else {
return Redirect::route('register')->withErrors($validation)->withInput();
}
}
public function getLogin() {
return View::make('users.login')->with('title', 'Project - Login');
}
public function postLogin()
{
$user = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
$validator = Validator::make($user, User::$rules);
if ($validator->passes()) {
if (Auth::attempt($user)) {
return Redirect::to('home');
}
else
{
return Redirect::to('login')->withErrors($validator)->withInput();
}
}
return Redirect::to('login')->withErrors($validator)->withInput();
}
和路由: 的用户名已被占用:当我尝试登录
Route::get('/', array('as' => 'home', 'uses' => '[email protected]'));
Route::get('register', array('as' => 'register', 'uses' => '[email protected]'));
Route::get('login', array('as' => 'login', 'uses' => '[email protected]'));
Route::post('register', array('before' => 'csrf', 'uses' => '[email protected]'));
Route::post('login', array('before' => 'csrf', 'uses' => '[email protected]'));
错误。 密码确认不匹配。
我以前使用过这个代码,它工作,但现在的问题是什么,我不知道。
你可以分享你的$ rules数组吗? – Dru
公共静态$规则=阵列( \t \t '用户名'=> '必需|独特:用户| AlphaDash |民:4', \t \t '密码'=> '必需| AlphaNum |证实', \t \t“ password_confirmation'=>'必须| AlphaNum' \t); – milos