我在保存表单中的值后尝试保存用户的详细信息。我编写了一个控制器来发布用户详细信息并将其保存在数据库中,但是user-> save()似乎对我不起作用。
public function postAddBusiness()
{
$rules = array(
'email' => 'required|email',
'password' => 'same:password_confirm',
'name' => 'required',
'business-type' => 'required'
);
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
return Redirect::to('business/add')->withErrors($validation)->withInput();
}
$user = new User;
$user->email = Input::get('email');
if (Input::get('password'))
{
$user->password = Hash::make(Input::get('password'));
}
$user->name = Input::get('name');
$user->type = Input::get('business-type');
//$he= $user->save();
if ($user->save())
{
return Redirect::to('dashboard')->with('notify','Information updated');
}
print_r($user);
}
当我返回数组$ user时,我得到了我在表单中输入的值。
User Object ( [connection:protected] => [table:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ( [email] => b1@b.com [password] => $2y$10$KWGRMooHxavSbnhcGKqnNe19hstF44lPjVkseX5BwJ.HYUzRzzg7m [name] => B1 [type] => plumber ) [original:protected] => Array ( ) [relations:protected] => Array ( ) [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [appends:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => [errors] => Illuminate\Support\MessageBag Object ( [messages:protected] => Array ( [username] => Array ( [0] => The username field is required. ) [password_confirmation] => Array ( [0] => Wrong confirmation code. ) ) [format:protected] => :message ) )
我哪里错了?