我在以下内容上收到错误:
$user->email = Input::get('email');
我真的不确定代码有什么问题,看起来非常好。我查找了变量错误,只是缺少一个括号或半冒号。但据我所知,这似乎很好。
如果有人能帮助我,那就太好了。
如果还有其他代码,您可以将其列为评论,我会很乐意添加它。
谢谢!
public function doRegister()
{
$rules = array(
'name' => 'required|min:3', // name
'email' => 'required|email', // make sure the email is an actual email
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()){
// validation not successful, send back to form
Redirect::back()->withErrors;
} else {
$user = Input::all();
User::addNewUser();
if (Auth::attempt($user)) {
return Redirect::to('member');
}
}
}
用户模型
public static function addNewUser()
{
$user = new User;
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
}
答案 0 :(得分:3)
这是因为$user->save;
它是method
而不是property
,它应该被称为
$user->save();
而不是
$user->save;
更新:此外,它是U
而不是u
$user = new user;
应该是
$user = new User; // capital U
此外,在if ($validator->fails())
Redirect::back()->withErrors;
应该是
return Redirect::back()->withErrors($validator);
更新:因此,在修复3
错误(到目前为止)之后,您的完整代码应为
public function doRegister()
{
$rules = array(
'name' => 'required|min:3',
'email' => 'required|email',
'password' => 'required|alphaNum|min:3'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()){
return Redirect::back()->withErrors($validator);
}
else {
$user = new User;
$user->name =Input::get('name');
$user->email= Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
if (Auth::attempt($user)) {
return Redirect::to('member');
}
}
}