所以我正在尝试使用Laravel Framwork进行登录和注册系统。我运行时没有任何错误,但是当我尝试创建用户时,它不会进入数据库。 这是我的功能。
public function postRegister()
{
$input = Input::all();
$rules = array("username" => "required|unique:users|email", "password" => "required");
$v = Validator::make($input, $rules);
if($v->passes())
{
$user = new User();
$password = $input["password"];
$password = Hash::make($password);
$user = new User();
$user->username = $input["username"];
$user->email = $input["email"];
$user->password = $password;
$user->save();
return Redirect::to("login");
echo 'Succes, now you can log in!';
} else{
return Redirect::to("register");
echo 'Someting went wrong, try again!';
}
}
在这里,您可以看到我的register.blade
<!doctype html>
<html>
<head>
<title>Register</title>
</head>
<body>
{{ Form::open(array('url' => 'register')) }}
<h1>Register</h1>
<!-- if there are login errors, show them here -->
@if (Session::get('registerError'))
<div class="alert alert-danger">{{ Session::get('registerError') }}</div>
@endif
<p>
{{ $errors->first('username') }}
{{ $errors->first('email') }}
{{ $errors->first('password') }}
</p>
<p>
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('placeholder' => 'Choose Username')) }}
</p>
<p>
{{ Form::label('email', 'Email Address') }}
{{ Form::text('email', Input::old('email'), array('placeholder' => 'awesome@awesome.com')) }}
</p>
<p>
{{ Form::label('password', 'Password') }}
{{ Form::password('password') }}
</p>
<p>{{ Form::submit('Register') }}</p>
<p>{{HTML::link("login", "Back to login")}}</p>
{{ Form::close() }}
</body>
</html>
也许我只是错过了什么!